//
// Created by yuhaibo on 18-11-16.
//

#define LOG_TAG "Ota_HAL"
#define LOG_NDEBUG 0
#include "Ota.h"
#include <log/log.h>
#include <cinttypes>
#include <cstring>
#include "asn/src/APPInstallationConsent.h"
#include "asn/src/ConnectivitySts.h"
#include "asn/src/DownloadConsent.h"
#include "asn/src/ErrorCodes.h"
#include "asn/src/InstallationConsent.h"
#include "asn/src/OTAAssignmentSync.h"
#include "asn/src/OTADownloadprogress.h"
#include "asn/src/OTAHMILanguageSettings.h"
#include "asn/src/OTATCAMAssignmentNotification.h"
#include "asn/src/PDUHeader.h"
#include "asn/src/SharedElements.h"
#include "asn/src/SyncSchInstallTime.h"
#include "asn/src/UserOTASettings.h"
#include "asn/src/BSSIDDisplayedVersionSync.h"
#include "asn/src/OTAURLInfo.h"
#include "asn/src/OTAAssignmentkeytoTargetECU.h"
#include "asn/src/OTADownloadStatus.h"
#include "asn/src/OTAWriteInstallationInstruction.h"
#include "asn/src/OTAExceptionReports.h"
#include "asn/src/OTASetAssignmentFileInfo.h"
#include "asn/src/OTASignatureCertificate.h"
#include "asn/src/OTAInstallationRegretTimeOut.h"
#include "asn/src/OTAPostInstallationInfonotification.h"
#include "asn/src/RVDCTransferlogsCRC.h"
#include "asn/src/RVDCVerificationCRCStatus.h"
#include "asn/src/RVDCLogInterruptedDataTransferRetry.h"
#include "data/TransferRvdcData.h"

namespace vendor {
namespace ecarx {
namespace xma {
namespace ota {
namespace V1_0 {
const struct { milliseconds common = 50ms; } gDefaultDelay;

using ::android::hardware::hidl_string;
using ::android::hardware::Return;
using ::android::hardware::Void;

// const unsigned int DTC_FLAG_STATE = 1;
// const int32_t DTC_CODE = 0xD08100;

int testMode = 0;

int mWriteInstallationInstructionHandleId = 0;
int mFileInfoHandleId = 0;
int mUrlInfoHandledId = 0;
int mAssignmentkeyHandleId = 0;
int mSignatureCertificateHandleId = 0;

static char buf[1500] = {
    0,
};

static ipcp_peer_t peer_ota_server = {
    .sk_type = IPCP_TRANSPORT_UDP,
    .peer_ip = PEER_IP,
    .peer_port = PEER_PORT,
};

static ipcp_peer_t peer_ota_vgm_server = {
    .sk_type = IPCP_TRANSPORT_UDP,
    .peer_ip = PEER_VGM_IP,
    .peer_port = PEER_VGM_PORT,
};

static ipcp_peer_t peer_ota_server_test = {
    .sk_type = IPCP_TRANSPORT_UDP,
    .peer_ip = TEST_LOCAL_IP,
    .peer_port = TEST_LOCAL_PORT,
};

uint16_t Connectivity_OperationIDs[20] = {OP_ID_DOWNLOAD_CONSENT,
                                          OP_ID_INSTALLATION_CONSENT,
                                          OP_ID_USER_OTA_SETTINGS,
                                          OP_ID_OTA_ASSIGNMENT_SYNC,
                                          OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION,
                                          OP_ID_OTA_DOWNLOAD_PROGRESS,
                                          OP_ID_OTA_HMI_LANGUAGESETTINGS,
                                          OP_ID_CONNECTIVITY_STATUS,
                                          OP_ID_APP_INSTALL_CONSENT,
                                          OP_ID_SYNC_SCH_INSTALL_TIME,
                                          OP_ID_BSSID_DISPLAYEDVERSION_SYNC,
                                          OP_ID_OTA_INSTALLATION_REGRET_TIMEOUT,
                                          OP_ID_OTA_DOWNLOAD_STATUS,
                                          OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU,
                                          OP_ID_OTA_URL_INFO,
                                          OP_ID_OTA_SIGNATURE_CERTIFICATE,
                                          OP_ID_OTA_EXCEPTION_REPORTS,
                                          OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION,
                                          OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO,
                                          OP_ID_OTA_POST_INSTALLATION};

void* cookie;

void ota_received_cb(ipcp_packet_t* packet, ipcp_peer_t peer);
void ota_error_cb(ipcp_packet_t* ipcp_packet, ipcp_stack_err_t error);
void init_ota_side(ipcp_transport_conf_t* config);
void init_ota_side_test(ipcp_transport_conf_t* config);
void init_ota_ipcp_internal();

void init_ota_side(ipcp_transport_conf_t* config) {
    config->service_id = SERVICE_ID;
    strcpy(config->host_ip, LOCAL_IP);
    config->host_port = LOCAL_PORT;
    config->sk_type = IPCP_TRANSPORT_UDP;
    config->vlan = VLAN;
    config->priority = PRIORITY;

    testMode = 0;
}

void init_ota_side_test(ipcp_transport_conf_t* config) {
    config->service_id = SERVICE_ID;
    strcpy(config->host_ip, TEST_LOCAL_IP);
    config->host_port = TEST_LOCAL_PORT;
    config->sk_type = IPCP_TRANSPORT_UDP;
    config->vlan = VLAN;
    config->priority = PRIORITY;

    testMode = 1;
}

/* void Ota::setupDtcnl() {
    ALOGI("%s", __func__);
    mDtcnl = IDtcnl::getService();
    if (mDtcnl != NULL) {
        ALOGV("IDtcnl getService success");
    } else {
        ALOGE("IDtcnl getService mDtcnl is NULL");
    }
} */
/* void Ota::reportDtc() {
    ALOGI("%s", __func__);
    if (mDtcnl != NULL) {
        if (mDtcnl->reportDtc(DTC_CODE, DTC_FLAG_STATE) == dtcnl::V1_0::StatusCode::SUCCESS) {
            ALOGV("reportDtc SUCCESS");
        } else {
            ALOGE("reportDtc failed");
        }
    } else {
        ALOGE("%s: IDtcnl mDtcnl is NULL", __func__);
    }
} */

void ota_error_cb(ipcp_packet_t* ipcp_packet, ipcp_stack_err_t error) {
    ALOGD("%s, ota recv error cb...", __func__);
    // sp<Ota> ota = Ota::getOta(cookie);
    switch (error) {
        case STACK_FAILURE_CREATE_SOCKET:
        case STACK_FAILURE_SET_VLAN:
        case STACK_FAILURE_BIND_SOCKET:
        case STACK_FAILURE_LISTEN_SOCKET:
        case STACK_FAILURE_ACCEPT_SOCKET:
        case STACK_FAILURE_CONNECT_SOCKET:
        case STACK_FAILURE_CREATE_THREAD:
            ipcp_cleanup();
            sleep(2);
            init_ota_ipcp_internal();
            break;
        case STACK_FAILURE_WFA_TIMEOUT:
            ALOGE("STACK_FAILURE_WFA_TIMEOUT");
            break;
        case STACK_FAILURE_WFR_TIMEOUT:
            ALOGE("STACK_FAILURE_WFR_TIMEOUT");
            break;
        /* case DIAG_ERROR_Code_Invalid_Protocl_Version:
        case DIAG_ERROR_CODE_SERVICE_ID_NOT_AVAILABLE:
        case DIAG_ERROR_Code_OperationID_Not_Available:
        case DIAG_ERROR_Code_OperationType_Not_Available:
        case DIAG_ERROR_Code_Invalid_Length: {
            ALOGE("Invalid IPCP patcket, report DTC");
            ota->reportDtc();
            break;
        } */
        default:
            ALOGE("ota_error_cb default case");
            break;
    }
}

PurposeHal handlePurpose(bool recall, bool safety, bool cybersecurity) {
    PurposeHal purpose;
    purpose.recall = recall;
    purpose.safety = safety;
    purpose.cybersecurity = cybersecurity;
    return purpose;
}

std::string convertOSOCTETToString(const int count, const OSOCTET data[]) {
    std::string str;
    for (auto i = 0; i < count; i++) {
        std::string temp(2,data[i]);
        str.append(temp);
    }
    return str;
}

/*
std::string OSOCTETToString(const int count, const OSOCTET data[]) {
    std::string str;
    for (auto i = 0; i < count; i++) {
        str.append(std::to_string(data[i]));
    }
    return str;
}*/

std::string OSOCTETToString(const int count, const OSOCTET data[]) {
    std::string str;
    std::string temp;
    char schar[16];

    for (auto i = 0; i < count; i++) {
        sprintf(schar, "%X",data[i] );
        temp = schar;
        if (temp.size() < 2) {
            temp = "0" + temp;
        }
        str.append(temp);
    }
    return str;
}

std::string ecuaddressToString(const int count, const OSOCTET data[]) {
    std::string str;
    for (auto i = 0; i < count; i++) {
        std::string temp = std::to_string(data[i]);
        if ( temp.size() < 2 ) {
            temp = "0" + std::to_string(data[i]);
        } else {
            temp = std::to_string(data[i]);
        }
        str.append(temp);
    }
    return str;
}

void handleDownloadConsent(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_DOWNLOAD_CONSENT  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_NOTIFICATION: {
            //ALOGE("OP_ID_DOWNLOAD_CONSENT OP_TYPE_NOTIFICATION decode. len = %d", len);
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpDownloadConsent_Notification data;
            ASN1C_OpDownloadConsent_Notification OpDownloadConsent_NotificationPDU(decodeBuffer, data);

            if (OpDownloadConsent_NotificationPDU.Decode()) {
                ALOGE("OP_ID_DOWNLOAD_CONSENT OP_TYPE_NOTIFICATION decode error");
            } else {
                // ALOGV("OP_ID_DOWNLOAD_CONSENT OP_TYPE_NOTIFICATION decode success");

                //通知上层ota service
                // sp<Ota> ota = Ota::getOta(cookie);
                // sp<IOtaClientCallback> callback = ota->getCallback();
                ALOGD("OP_ID_DOWNLOAD_CONSENT OP_TYPE_NOTIFICATION decode uuid = %s ",
                      data.installationorder.uuid);
                ALOGD("OP_ID_DOWNLOAD_CONSENT OP_TYPE_NOTIFICATION decode downloadconsent = %d",
                      data.downloadconsent);
            }
            break;
        }
        default: {
            //ALOGE("packet->header.op_type in OP_ID_DOWNLOAD_CONSENT default case error!");
            break;
        }
    }
}

void handleOTAAssignmentSync(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_OTA_ASSIGNMENT_SYNC  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
          //  ALOGE("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_REQUEST decode.");
            break;
        }
        case OP_TYPE_RESPONSE:
        case OP_TYPE_NOTIFICATION: {
           // ALOGE("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_NOTIFICATION decode.");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTAAssignmentSync_Response data;
            ASN1C_OpOTAAssignmentSync_Response OpOTAAssignmentSync_ResponsePDU(decodeBuffer, data);
            int stat = OpOTAAssignmentSync_ResponsePDU.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_NOTIFICATION decode error" "stat = %d", stat);
            } else {
                ALOGV("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_NOTIFICATION decode success..");

                //通知上层ota service
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                //ALOGV("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_NOTIFICATION setDownloadConsent start");
                //ota->setDownloadConsent(data.installationorder.uuid, true);

                if (callback != NULL) {
                    OpOTAAssignmentParamHal opOTAAssignmentParamHal;

                    opOTAAssignmentParamHal.installationorder = (char*)data.installationorder.uuid;
                    opOTAAssignmentParamHal.timestamp = data.isotimestamp.timestamp;
                    opOTAAssignmentParamHal.criticality = (char*)data.criticality;
                    opOTAAssignmentParamHal.purpose = handlePurpose(
                        data.purpose.recall, data.purpose.safety, data.purpose.cybersecurity);
                    opOTAAssignmentParamHal.workshop_installiation = data.workshop_installiation;
                    opOTAAssignmentParamHal.downloadsize = data.downloadsize;
                    opOTAAssignmentParamHal.totalinstallation_time = data.totalinstallation_time;
                    opOTAAssignmentParamHal.newstatus = (char*)data.newstatus;
                    opOTAAssignmentParamHal.title = (char*)data.title;
                    opOTAAssignmentParamHal.bssid = (char*)data.bssid;
                    opOTAAssignmentParamHal.displayedversion = (char*)data.displayedversion;
                    opOTAAssignmentParamHal.description = (char*)data.description;
                    opOTAAssignmentParamHal.reason = (char*)data.reason;
                    ALOGD("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_NOTIFICATION criticality = %s ",
                          data.criticality);
                    ALOGD("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_NOTIFICATION criticality = %s ",
                          opOTAAssignmentParamHal.criticality.c_str());
                    callback->onOTAAssignmentSyncNotification(opOTAAssignmentParamHal);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_ERROR decode error");
            } else {
              //ALOGV("OP_ID_OTA_ASSIGNMENT_SYNC OP_TYPE_ERROR decode success");
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    callback->onOTAAssignmentSyncError(data.errorCode, data.errorInfo);
                }
            }
            break;
        }
        default:
           //ALOGE("Incorret OP_TYPE.");
            break;
    }
}

void handleOTADownloadProgress(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_OTA_DOWNLOAD_PROGRESS  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_NOTIFICATION: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTADownloadprogress_NotificationCyclic data;
            ASN1C_OpOTADownloadprogress_NotificationCyclic OpOTADownloadprogress_Notification(decodeBuffer, data);
            int stat = OpOTADownloadprogress_Notification.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_OTA_DOWNLOAD_PROGRESS OP_TYPE_NOTIFICATION decode error " "stat = %d", stat);
            } else {
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    OpOTADownloadProgressNotifyHal opOTADownloadProgressNotifyHal;
                    opOTADownloadProgressNotifyHal.installationorder = (char*)data.installationorder.uuid;
                    opOTADownloadProgressNotifyHal.progressbar = data.progressbar;

                    callback->onOTADownloadProgressNotification(opOTADownloadProgressNotifyHal.progressbar);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_DOWNLOAD_PROGRESS decode error");
            } else {
                //ALOGV("OP_ID_OTA_DOWNLOAD_PROGRESS decode success");
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    callback->onOTADownloadProgressError(data.errorCode, data.errorInfo);
                }
            }
            break;
        }
        default:
            break;
    }
}

void handleOTATCAMAssignmentNotification(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            //ALOGE("OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION OP_TYPE_REQUEST decode.");
            break;
        }
        case OP_TYPE_RESPONSE: {
           //ALOGE("OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION OP_TYPE_RESPONSE decode.");
            break;
        }
        case OP_TYPE_NOTIFICATION: {
           //ALOGE("OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION OP_TYPE_NOTIFICATION decode.");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTATCAMAssignmentNotification_Notification data;
            ASN1C_OpOTATCAMAssignmentNotification_Notification
                OpOTATCAMAssignmentNotification_NotificationPDU(decodeBuffer, data);
            int stat = OpOTATCAMAssignmentNotification_NotificationPDU.Decode();
            if (stat != 0) {
                ALOGE(
                    "OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION OP_TYPE_NOTIFICATION decode error "
                    "stat = %d",
                    stat);
            } else {
                // ALOGV(
                //    "OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION OP_TYPE_NOTIFICATION decode "
                //     "success");
                //通知上层ota service
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    OpOTATCAMAssignmentParamHal opOTATCAMAssignmentParamHal;

                    opOTATCAMAssignmentParamHal.installationorder =
                        (char*)data.installationorder.uuid;
                    opOTATCAMAssignmentParamHal.timestamp = data.isotimestamp.timestamp;
                    opOTATCAMAssignmentParamHal.newstatus = (char*)data.newstatus;
                    opOTATCAMAssignmentParamHal.reason = (char*)data.reason;

                    callback->onOTATCAMAssignmentNotification(opOTATCAMAssignmentParamHal);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION OP_TYPE_ERROR decode error");
            } else {
               //ALOGV("OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION OP_TYPE_ERROR decode success");
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    callback->onOTATCAMAssignmentError(data.errorCode, data.errorInfo);
                }
            }
            break;
        }
        default:
           //ALOGE("Incorret OP_TYPE.");
            break;
    }
}

void handleOTAPostnstallation(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_OTA_POST_INSTALLATION  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_NOTIFICATION: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTAPostInstallationInfonotification_Notification data;
            ASN1C_OpOTAPostInstallationInfonotification_Notification
                OpOTAPostInstallationInfonotification_NotificationPDU(decodeBuffer, data);
            int stat = OpOTAPostInstallationInfonotification_NotificationPDU.Decode();
            if (stat != 0) {
                ALOGE(
                    "OP_ID_OTA_POST_INSTALLATION OP_TYPE_NOTIFICATION decode error "
                    "stat = %d",
                    stat);
            } else {
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    OpOTAPostInstallationParamHal paramHal;

                    paramHal.installationorder =
                        (char*)data.installationorder.uuid;
                    paramHal.timestamp = data.isotimestamp.timestamp;
                    paramHal.newstatus = (char*)data.newstatus;
                    paramHal.reason = (char*)data.reason;

                    callback->onOTAPostInstallationInfonotification(paramHal);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            break;
        }
        default:
            break;
    }
}

void handleConnectivityStatus(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_CONNECTIVITY_STATUS  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            //ALOGE("OP_ID_CONNECTIVITY_STATUS OP_TYPE_REQUEST decode.");
            break;
        }
        case OP_TYPE_RESPONSE:
        case OP_TYPE_NOTIFICATION: {
            //ALOGE("OP_ID_CONNECTIVITY_STATUS OP_TYPE_NOTIFICATION decode.");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpConnectivityStatus_Response data;
            ASN1C_OpConnectivityStatus_Response OpConnectivityStatus_ResponsePDU(decodeBuffer, data);
            int stat = OpConnectivityStatus_ResponsePDU.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_CONNECTIVITY_STATUS OP_TYPE_NOTIFICATION decode error stat = %d ",
                      stat);
            } else {
                ALOGD("OP_ID_CONNECTIVITY_STATUS OP_TYPE_NOTIFICATION decode success");
                //通知上层ota service
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    ALOGD("OP_ID_CONNECTIVITY_STATUS OP_TYPE_NOTIFICATION decode status is = %d ",
                          data.connectionStatus);
                    ConnectivityStsHal conStatus;
                    conStatus.connectionStatus = data.connectionStatus;
                    callback->onConnectivityStsNotification(conStatus);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_CONNECTIVITY_STATUS OP_TYPE_ERROR decode error");
            } else {
                //ALOGV("OP_ID_CONNECTIVITY_STATUS OP_TYPE_ERROR decode success");
            }
            break;
        }
        default:
            //ALOGE("Incorret OP_TYPE.");
            break;
    }
}

void handleAppInstallConsent(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_APP_INSTALL_CONSENT  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            //ALOGE("OP_ID_APP_INSTALL_CONSENT OP_TYPE_REQUEST decode.");
            break;
        }
        case OP_TYPE_RESPONSE: {
            //ALOGE("OP_ID_APP_INSTALL_CONSENT OP_TYPE_RESPONSE decode.");
            break;
        }
        case OP_TYPE_NOTIFICATION: {
            //ALOGE("OP_ID_APP_INSTALL_CONSENT OP_TYPE_NOTIFICATION decode.");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpAPPInstallationConsent_Notification data;
            ASN1C_OpAPPInstallationConsent_Notification OpAPPInstallationConsent_NotificationPDU(
                decodeBuffer, data);
            int stat = OpAPPInstallationConsent_NotificationPDU.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_APP_INSTALL_CONSENT OP_TYPE_NOTIFICATION decode error stat = %d ",
                      stat);
            } else {
                //ALOGD("OP_ID_APP_INSTALL_CONSENT OP_TYPE_NOTIFICATION decode success");
                //通知上层ota service
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    APPInstallationConsentHal appInsConsentHal;
                    appInsConsentHal.installationorder = (char*)data.installationorder.uuid;
                    appInsConsentHal.appinstallationconsent =
                        static_cast<AppInstallationConsent>(data.appinstallationconsent);
                    appInsConsentHal.deltatime = data.deltatime;
                    callback->onAPPInstallationConsentNotification(appInsConsentHal);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_APP_INSTALL_CONSENT OP_TYPE_ERROR decode error");
            } else {
                //ALOGV("OP_ID_APP_INSTALL_CONSENT OP_TYPE_ERROR decode success");
            }
            break;
        }
        default:
            //ALOGE("Incorret OP_TYPE.");
            break;
    }
}

void handleSyncSchInstallTime(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_SYNC_SCH_INSTALL_TIME  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            //ALOGE("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_REQUEST decode.");
            break;
        }
        case OP_TYPE_NOTIFICATION: {
            //ALOGE("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_NOTIFICATION decode.");
            break;
        }
        case OP_TYPE_RESPONSE: {
            //ALOGE("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_RESPONSE decode.");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpSyncSchInstallTime_Response data;
            ASN1C_OpSyncSchInstallTime_Response OpSyncSchInstallTime_ResponsePDU(decodeBuffer, data);
            int stat = OpSyncSchInstallTime_ResponsePDU.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_RESPONSE decode error stat = %d ", stat);
            } else {
                //ALOGD("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_RESPONSE decode success");
                //通知上层ota service
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    SyncSchInstallTimeHal syncSchInsTime;
                    syncSchInsTime.schInstalldeltatime = data.schInstalldeltatime;
                    callback->onSyncSchInstallTimeNotification(syncSchInsTime);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_ERROR decode error");
            } else {
                //ALOGV("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_ERROR decode success");
            }
            break;
        }
        default:
            //ALOGE("Incorret OP_TYPE.");
            break;
    }
}

void handleBSSIDDisplayedVersionSync(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    ALOGD("OP_ID_BSSID_DISPLAYEDVERSION_SYNC  operation_id = %x", packet->header.op_type);
    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            //ALOGE("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_REQUEST decode.");
            break;
        }
        case OP_TYPE_NOTIFICATION: {
            //ALOGE("OP_ID_SYNC_SCH_INSTALL_TIME OP_TYPE_NOTIFICATION decode.");
            break;
        }
        case OP_TYPE_RESPONSE: {
            //ALOGE("OP_ID_BSSID_DISPLAYEDVERSION_SYNC OP_TYPE_RESPONSE decode.");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpBSSIDDisplayedVersionSync_Response data;
            ASN1C_OpBSSIDDisplayedVersionSync_Response OpBSSIDDisplayedVersionSync_ResponsePDU(decodeBuffer, data);
            int stat = OpBSSIDDisplayedVersionSync_ResponsePDU.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_BSSID_DISPLAYEDVERSION_SYNC OP_TYPE_RESPONSE decode error stat = %d ", stat);
            } else {
                //ALOGD("OP_ID_BSSID_DISPLAYEDVERSION_SYNC OP_TYPE_RESPONSE decode success");
                //通知上层ota service
                sp<Ota> ota = Ota::getOta(cookie);
                sp<IOtaClientCallback> callback = ota->getCallback();

                if (callback != NULL) {
                    OpBSSIDDisplayedVersionSyncHal opBSSIDDisplayedVersionSyncHal;
                    opBSSIDDisplayedVersionSyncHal.bssid = (char*)data.bssid;
                    opBSSIDDisplayedVersionSyncHal.displayedversion = (char*)data.displayedversion;
                    callback->onBSSIDDisplayedVersionSyncNotification(opBSSIDDisplayedVersionSyncHal);
                }
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_BSSID_DISPLAYEDVERSION_SYNC OP_TYPE_ERROR decode error");
            } else {
                //ALOGV("OP_ID_BSSID_DISPLAYEDVERSION_SYNC OP_TYPE_ERROR decode success");
            }
            break;
        }
        default:
            //ALOGE("Incorret OP_TYPE.");
            break;
    }
}

void handleAssignmentkeytoTargetECU(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;

    sp<Ota> ota = Ota::getOta(cookie);
    sp<IOtaClientCallback> callback = ota->getCallback();
    if (callback == NULL) {
        ALOGE("OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU  : callback is null !");
        return;
    }
    ALOGD("OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU  operation_id = %x", packet->header.op_type);

    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTAAssignmentkeytoTargetECU_Request data;
            ASN1C_OpOTAAssignmentkeytoTargetECU_Request opOTAAssignmentkeytoTargetECU_Request(decodeBuffer, data);
            int stat = opOTAAssignmentkeytoTargetECU_Request.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU       OP_TYPE_REQUEST decode error stat = %d ", stat);
            } else {
                ALOGD("OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU       OP_TYPE_REQUEST  decode success");
                mAssignmentkeyHandleId = header->senderHandleId;
                OpAssignmentkeytoTargetECUHal param;
                param.installationorder = (char*)data.installationorder.uuid;
                param.isotimestamp = (char*)data.isotimestamp.timestamp;
                param.fileencryptiontype = OSOCTETToString(data.fileencryptiontype.numocts,  data.fileencryptiontype.data);
                param.secretkey = OSOCTETToString(data.secretkey.numocts,  data.secretkey.data);
                callback->onAssignmentkeytoTargetECUReqHal( param );
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU     OP_TYPE_ERROR    decode error");
            } else {
                //callback->onAssignmentkeytoTargetECUErrInfo(data.errorCode, data.errorInfo);
            }
            break;
        }
        default:
            break;
    }
}

void handleOTASignatureCertificate(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;

    sp<Ota> ota = Ota::getOta(cookie);
    sp<IOtaClientCallback> callback = ota->getCallback();
    if (callback == NULL) {
        ALOGE("OP_ID_OTA_SIGNATURE_CERTIFICATE  : callback is null !");
        return;
    }
    ALOGD("OP_ID_OTA_SIGNATURE_CERTIFICATE  operation_id = %x", packet->header.op_type);

    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTASignatureCertificate_Request data;
            ASN1C_OpOTASignatureCertificate_Request opOTASignatureCertificate_Request(decodeBuffer, data);
            int stat = opOTASignatureCertificate_Request.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_OTA_SIGNATURE_CERTIFICATE       OP_TYPE_REQUEST decode error stat = %d ", stat);
            } else {
                mSignatureCertificateHandleId = header->senderHandleId;
                ALOGD("OP_ID_OTA_SIGNATURE_CERTIFICATE       OP_TYPE_REQUEST  decode success");
                callback->onSignatureCertificateReqHal((const char*)data.oTASignatureCertificate);
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ALOGE("OP_ID_OTA_SIGNATURE_CERTIFICATE   OP_TYPE_ERROR");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_SIGNATURE_CERTIFICATE   OP_TYPE_ERROR    decode error");
            } else {
                //callback->onAssignmentkeytoTargetECUErrInfo(data.errorCode, data.errorInfo);
            }
            break;
        }
        default:
            break;
    }
}

void handleOTAWriteInstallationInstruction(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;

    sp<Ota> ota = Ota::getOta(cookie);
    sp<IOtaClientCallback> callback = ota->getCallback();
    if (callback == NULL) {
        ALOGE("OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION  : callback is null !");
        return;
    }
    ALOGD("OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION  operation_id = %x", packet->header.op_type);

    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {//for temp
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTAWriteInstallationInstructions_Request data;
            ASN1C_OpOTAWriteInstallationInstructions_Request opOTAWriteInstallationInstructions_Request(decodeBuffer, data);
            int stat = opOTAWriteInstallationInstructions_Request.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION       OP_TYPE_REQUEST decode error stat = %d ", stat);
            } else {
                ALOGD("OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION       OP_TYPE_REQUEST  decode success");
                mWriteInstallationInstructionHandleId = header->senderHandleId;
                OpOTAWriteInstallationInstructionHal param;
                param.installationorder = (char*)data.installationorder.uuid;
                param.sblnotpresent = data.installationinstruction.ecuinstructions.sblnotpresent;
                param.ecuaddress = ecuaddressToString(data.installationinstruction.ecuinstructions.ecuaddress.addr.numocts,
                                                            data.installationinstruction.ecuinstructions.ecuaddress.addr.data);

                ALOGD("handleOTAWriteInstallationInstruction ecuaddress = %s", param.ecuaddress.c_str());

                if(data.installationinstruction.ecuinstructions.softwarepartinstallationinstruction.count > 0) {
                    std::vector<SoftwarePartInstallationInstruction> infoList;
                    ASN1C_Ecuinstructionsdata_softwarepartinstallationinstruction softwarepartinstallationinstructionList(
                        data.installationinstruction.ecuinstructions.softwarepartinstallationinstruction);
                        auto list = softwarepartinstallationinstructionList.iterator();

                        while (list->hasNext()) {
                            auto item = static_cast<ASN1T_SoftwarePartInstallationInstruction*>(list->next());
                            SoftwarePartInstallationInstruction info;
                            info.filename = (char*)item->filename.name;
                            info.downloadtype = (char*)item->downloadtype;
                            info.installationtype = (char*)item->installationtype;
                            info.fileencryptiontype = (char*)item->fileencryptiontype;
                            info.estimatedinstallationtime = (int32_t)item->estimatedinstallationtime;

                            ALOGD("handleOTAWriteInstallationInstruction filename = %s", item->filename.name);
                            ALOGD("handleOTAWriteInstallationInstruction downloadtype = %s", item->downloadtype);
                            ALOGD("handleOTAWriteInstallationInstruction installationtype = %s", item->installationtype);
                            ALOGD("handleOTAWriteInstallationInstruction fileencryptiontype = %s", item->fileencryptiontype);
                            ALOGD("handleOTAWriteInstallationInstruction estimatedinstallationtime = %d", item->estimatedinstallationtime);

                            infoList.push_back(info);
                        }
                        param.dataList = infoList;
                }
               callback->onWriteInstallationInstructionReqHal(param);
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ALOGE("OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION   OP_TYPE_ERROR");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION   OP_TYPE_ERROR    decode error");
            } else {
                //callback->onAssignmentkeytoTargetECUErrInfo(data.errorCode, data.errorInfo);
            }
            break;
        }
        default:
            break;
    }
}

void handleOTAAssignmentFileInfo(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;

    sp<Ota> ota = Ota::getOta(cookie);
    sp<IOtaClientCallback> callback = ota->getCallback();
    if (callback == NULL) {
        ALOGE("OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO  : callback is null !");
        return;
    }
    ALOGD("OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO  operation_id = %x", packet->header.op_type);

    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTASetAssignmentFileInfo_Request data;
            ASN1C_OpOTASetAssignmentFileInfo_Request opOTASetAssignmentFileInfo_Request(decodeBuffer, data);
            int stat = opOTASetAssignmentFileInfo_Request.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO       OP_TYPE_RESPONSE decode error stat = %d ", stat);
            } else {
                ALOGD("OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO       OP_TYPE_RESPONSE  decode success");
                mFileInfoHandleId = header->senderHandleId;
                OpOTASetAssignmentFileInfoHal param;
                param.installationorder =  (char*)data.installationorder.uuid;
                param.ecuaddress = ecuaddressToString(data.ecuaddress.addr.numocts,
                                                            data.ecuaddress.addr.data);
                param.lastsegment = data.lastsegment;

                if (data.assignfileinfo.count > 0) {
                     std::vector<AssignmentFileInfo> infoList;
                     ASN1C__SetOfAssignmentFileInfo assignmentFileInfoList(data.assignfileinfo);
                     auto list = assignmentFileInfoList.iterator();

                     while (list->hasNext()) {
                         auto item = static_cast<ASN1T_AssignmentFileInfo*>(list->next());
                         AssignmentFileInfo info;
                         info.filename = (char*)item->filename.name;
                         info.downloadtype = OSOCTETToString(item->downloadtype.numocts, item->downloadtype.data);
                         info.installationtype = OSOCTETToString(item->installationtype.numocts, item->installationtype.data);
                         info.softwarepartsignature = OSOCTETToString(item->softwarepartsignature.softwarepartsignature1.numocts,
                                                                                        item->softwarepartsignature.softwarepartsignature1.data);
                         info.filechecksum = OSOCTETToString(item->filechecksum.numocts,
                                                                                        item->filechecksum.data);

                         infoList.push_back(info);
                     }

                     param.dataList = infoList;
                }

               callback->onAssignmentFileInfoReqHal(param);
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ALOGE("OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO   OP_TYPE_ERROR");
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO   OP_TYPE_ERROR    decode error");
            } else {
                //callback->onAssignmentkeytoTargetECUErrInfo(data.errorCode, data.errorInfo);
            }
            break;
        }
        default:
            break;
    }
}

void handleOTAURLInfo(ipcp_packet_t* packet) {
    if (packet == nullptr) return;

    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;

    sp<Ota> ota = Ota::getOta(cookie);
    sp<IOtaClientCallback> callback = ota->getCallback();
    if (callback == NULL) {
        ALOGE("OP_ID_OTA_URL_INFO  : callback is null !");
        return;
    }
    ALOGD("OP_ID_OTA_URL_INFO  operation_id = %x", packet->header.op_type);

    switch (packet->header.op_type) {
        case OP_TYPE_REQUEST: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
            decodeBuffer.setTrace(true);
            decodeBuffer.setDiag(true);
            ASN1T_OpOTAURLInfo_Request data;
            ASN1C_OpOTAURLInfo_Request OpOTAURLInfo_Request(decodeBuffer, data);
            int stat = OpOTAURLInfo_Request.Decode();
            if (stat != 0) {
                ALOGE("OP_ID_OTA_URL_INFO       OP_TYPE_REQUEST decode error stat = %d ", stat);
            } else {
                ALOGD("OP_ID_OTA_URL_INFO       OP_TYPE_REQUEST  decode success");
                mUrlInfoHandledId = header->senderHandleId;
                OpOTAURLInfoReqHal opOTAURLInfoReqHal;
                opOTAURLInfoReqHal.installationorder = (char*)data.installationorder.uuid;
                opOTAURLInfoReqHal.ecuaddress = ecuaddressToString(data.ecuaddress.addr.numocts, data.ecuaddress.addr.data);
                opOTAURLInfoReqHal.downloadtype = OSOCTETToString(data.downloadtype.numocts, data.downloadtype.data);
                opOTAURLInfoReqHal.encryptiontype = OSOCTETToString(data.encryptiontype.numocts, data.encryptiontype.data);
                opOTAURLInfoReqHal.encryptinfo = OSOCTETToString(data.encryptinfo.numocts, data.encryptinfo.data);
                opOTAURLInfoReqHal.fileSize = data.fileSize;

                if (data.specifiedurl.count > 0) {
                    std::vector<Specifiedurl> urlList;
                    ASN1C__SetOfSpecifiedurl setOfSpecifiedurlList(data.specifiedurl);
                    auto list = setOfSpecifiedurlList.iterator();

                    while (list->hasNext()) {
                        Specifiedurl info;
                        auto item = static_cast<ASN1T_Specifiedurl*>(list->next());
                        info.url = (char*)item->url;
                        urlList.push_back( info );
                    }
                    opOTAURLInfoReqHal.urlList = urlList;
                }
                callback->onOTAURLInfoReqHal(opOTAURLInfoReqHal);
            }
            break;
        }
        case OP_TYPE_ERROR: {
            ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, true);
            ASN1T_OpGeneric_Error data;
            ASN1C_OpGeneric_Error OpGeneric_ErrorPUD(decodeBuffer, data);

            if (OpGeneric_ErrorPUD.Decode()) {
                ALOGE("OP_ID_OTA_URL_INFO     OP_TYPE_ERROR    decode error");
            } else {
                callback->onOTAURLInfoErrorHal(data.errorCode, data.errorInfo);
            }
            break;
        }
        default:
            break;
    }
}

void handleOTAUserOTASettings(ipcp_packet_t* packet) {
     if (packet == nullptr) return;

     ipcp_header_t* header = &packet->header;
     uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
     ALOGD("OP_ID_USER_OTA_SETTINGS  operation_id = %x", packet->header.op_type);

     switch (packet->header.op_type) {
         case OP_TYPE_NOTIFICATION: {
             //ALOGE("OP_ID_USER_OTA_SETTINGS OP_TYPE_NOTIFICATION decode. len = %d", len);
             ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
             decodeBuffer.setTrace(true);
             decodeBuffer.setDiag(true);
             ASN1T_OpUserOTASettings_Notification data;
             ASN1C_OpUserOTASettings_Notification opUserOTASettings_NotificationPDU(decodeBuffer,
                 data);

             if (opUserOTASettings_NotificationPDU.Decode()) {
                 ALOGE("OP_ID_USER_OTA_SETTINGS OP_TYPE_NOTIFICATION decode error");
             } else {
                 // ALOGV("OP_ID_USER_OTA_SETTINGS OP_TYPE_NOTIFICATION decode success");

                 //通知上层ota service
                 sp<Ota> ota = Ota::getOta(cookie);
                 sp<IOtaClientCallback> callback = ota->getCallback();
                 if (callback != NULL) {
                     OpOTAUserOtaSettingsHal opOTAUserOtaSettingsHal;
                     opOTAUserOtaSettingsHal.otasetting = data.userOTASetting.otasetting;
                     opOTAUserOtaSettingsHal.autosync = data.userOTASetting.autosync;
                     opOTAUserOtaSettingsHal.autodownload = data.userOTASetting.autodownload;
                     opOTAUserOtaSettingsHal.autoinstallation = data.userOTASetting.autoinstallation;

                     auto ret = callback->onOTAUserSettings(opOTAUserOtaSettingsHal);
                     if (!ret.isOk()) {
                         ALOGE("%s: Unable to invoke callback", __func__);
                     }
                 }
                 std::string otasetting_status = std::to_string(data.userOTASetting.otasetting);
                 std::string autosync_status = std::to_string(data.userOTASetting.autosync);
                 std::string autodownload_status = std::to_string(data.userOTASetting.autodownload);
                 std::string autoinstall_status = std::to_string(data.userOTASetting.autoinstallation);
                 android::base::SetProperty(OTA_SETTING, otasetting_status);
                 android::base::SetProperty(OTA_AUTO_SYNC, autosync_status);
                 android::base::SetProperty(OTA_AUTO_DOWNLOAD, autodownload_status);
                 android::base::SetProperty(OTA_AUTO_INSTALL, autoinstall_status);
                 ALOGD("OP_ID_USER_OTA_SETTINGS OP_TYPE_NOTIFICATION decode otasetting = %d ",
                     data.userOTASetting.otasetting);
                 ALOGD("OP_ID_USER_OTA_SETTINGS OP_TYPE_NOTIFICATION decode autosync = %d",
                     data.userOTASetting.autosync);
                 ALOGD("OP_ID_USER_OTA_SETTINGS OP_TYPE_NOTIFICATION decode autodownload = %d",
                      data.userOTASetting.autodownload);
                 ALOGD("OP_ID_USER_OTA_SETTINGS OP_TYPE_NOTIFICATION decode autoinstallation = %d",
                      data.userOTASetting.autoinstallation);
             }
             break;
         }
         default: {
             //ALOGE("packet->header.op_type in OP_ID_DOWNLOAD_CONSENT default case error!");
             break;
         }
     }
}

void handleTransferLogsCRC(ipcp_packet_t* packet) {
     if (packet == nullptr) return;

     ipcp_header_t* header = &packet->header;
     uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
     ALOGD("OP_ID_RVDC_TRANSFER_LOGS_CRC  operation_id = %x", packet->header.op_type);

     switch (packet->header.op_type) {
         case OP_TYPE_REQUEST: {
             //ALOGE("OP_ID_RVDC_TRANSFER_LOGS_CRC OP_TYPE_REQUEST decode. len = %d", len);
             ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
             decodeBuffer.setTrace(true);
             decodeBuffer.setDiag(true);
             ASN1T_OpRVDCTransferLogsCRC_Request data;
             ASN1C_OpRVDCTransferLogsCRC_Request opTransferLogsCRC_Request(decodeBuffer, data);

             if (opTransferLogsCRC_Request.Decode()) {
                 ALOGE("OP_ID_RVDC_TRANSFER_LOGS_CRC OP_TYPE_REQUEST decode error");
             } else {
                 // ALOGV("OP_ID_RVDC_TRANSFER_LOGS_CRC OP_TYPE_REQUEST decode success");

                 //通知上层ota service
                 sp<Ota> ota = Ota::getOta(cookie);
                 sp<IOtaClientCallback> callback = ota->getCallback();
                 if (callback != NULL) {
                     RVDCTransferLogsCRCRequest opTransferLogsCRC;
                     LogName logName;
                     logName.logname = (char*)data.logname.name;
                     opTransferLogsCRC.logname = logName;
                     opTransferLogsCRC.logcrc = OSOCTETToString(data.logcrc.numocts,  data.logcrc.data);;

                     auto ret = callback->onRVDCTransferLogsCRC(opTransferLogsCRC);
                     if (!ret.isOk()) {
                         ALOGE("%s: Unable to invoke callback", __func__);
                     }
                 }
             }
             break;
         }
         default: {
             //ALOGE("packet->header.op_type in OP_ID_RVDC_TRANSFER_LOGS_CRC default case error!");
             break;
         }
     }
}

void handleRVDCTransferLogsData(ipcp_packet_t* packet) {
     if (packet == nullptr) return;
     ALOGD("OP_ID_RVDC_TRANSFER_LOGS_DATA  operation_id = %x", packet->header.op_type);
     switch (packet->header.op_type) {
         case OP_TYPE_REQUEST: {
            //通知上层ota service
             sp<Ota> ota = Ota::getOta(cookie);
             sp<IOtaClientCallback> callback = ota->getCallback();
             if (callback != NULL) {
                 TransferRvdcData buffData;
                 buffData.parseRVDCBuf((char*)packet->payload);

                 TransRVDCLogData data;
                 data.logname = buffData.mLogname;
                 data.chunknumber = buffData.mChunknumber;
                 data.filesize = buffData.mFileSize;
                 data.chunksize = buffData.mChunkSize;
                 data.chunkpayload = std::vector(buffData.mChunkPayload, buffData.mChunkPayload + buffData.mChunkSize);
                 callback->onRVDCTransLogData(data);
             }
             break;
         }
         default: {
             //ALOGE("packet->header.op_type in OP_ID_RVDC_TRANSFER_LOGS_DATA default case error!");
             break;
         }
     }
}

void handleLogTransferRetry(ipcp_packet_t* packet) {
     if (packet == nullptr) return;

     ipcp_header_t* header = &packet->header;
     uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
     ALOGD("OP_ID_RVDC_LOG_TRANSFER_RETRY  operation_id = %x", packet->header.op_type);

     switch (packet->header.op_type) {
         case OP_TYPE_REQUEST: {
             //ALOGE("OP_ID_RVDC_LOG_TRANSFER_RETRY OP_TYPE_REQUEST decode. len = %d", len);
             ASN1PERDecodeBuffer decodeBuffer((OSOCTET*)packet->payload, len, false);
             decodeBuffer.setTrace(true);
             decodeBuffer.setDiag(true);
             ASN1T_OpRVDCLogInterruptedDataTransferRetry_Request data;
             ASN1C_OpRVDCLogInterruptedDataTransferRetry_Request opLogTransferRetry_Request(decodeBuffer, data);

             if (opLogTransferRetry_Request.Decode()) {
                 ALOGE("OP_ID_RVDC_LOG_TRANSFER_RETRY OP_TYPE_REQUEST decode error");
             } else {
                 // ALOGV("OP_ID_RVDC_LOG_TRANSFER_RETRY OP_TYPE_REQUEST decode success");

                 //通知上层ota service
                 sp<Ota> ota = Ota::getOta(cookie);
                 sp<IOtaClientCallback> callback = ota->getCallback();
                 if (callback != NULL) {
                     RVDCLogInterruptedDataTransferRetryRequest opDataTransferRetry;
                     LogName logName;
                     logName.logname = (char*)data.logname.name;
                     opDataTransferRetry.logname = logName;
                     auto ret = callback->onRVDCLogInterruptedDataTransferRetry(opDataTransferRetry);
                     if (!ret.isOk()) {
                         ALOGE("%s: Unable to invoke callback", __func__);
                     }
                 }
             }
             break;
         }
         default: {
             //ALOGE("packet->header.op_type in OP_ID_RVDC_LOG_TRANSFER_RETRY default case error!");
             break;
         }
     }
}

void ota_received_cb(ipcp_packet_t* packet, ipcp_peer_t peer) {
    ipcp_header_t* header = &packet->header;
    uint16_t len = header->length - ASN_HEADER_LENGTH_OFFSET;
    //ALOGV("<-------------------------------------------------------------------->");
    ALOGV("<--------------ota hal receive package info--------------------->");
    ALOGV("%s, received ipcp header : sid: %#x, op_id: %#x, op_type: %#x", __func__,
          header->service_id, header->operation_id, header->op_type);
    //ALOGV("<-------------------------------------------------------------------->");
    std::string otasettingProperty = android::base::GetProperty(OTA_SETTING, "");
    std::string autosyncProperty = android::base::GetProperty(OTA_AUTO_SYNC, "");
    ALOGD("%s, otasettingProperty is %s", __func__, otasettingProperty.c_str());
    ALOGD("%s, autosyncProperty is %s", __func__, autosyncProperty.c_str());
    if ("0" == otasettingProperty) {
        return;
    }
    if (header->service_id != SERVICE_ID_OTA) {
        ALOGE("%s, invalid service id %hu detected !!!\n", __func__, header->service_id);
        return;
    }
    switch (header->operation_id) {
        case OP_ID_DOWNLOAD_CONSENT:
            handleDownloadConsent(packet);
            break;
        case OP_ID_OTA_ASSIGNMENT_SYNC:
            if ("0" == autosyncProperty) {
               break;
            }
            handleOTAAssignmentSync(packet);
            break;
        case OP_ID_OTA_DOWNLOAD_PROGRESS:
            handleOTADownloadProgress(packet);
            break;
        case OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION:
            handleOTATCAMAssignmentNotification(packet);
            break;
        case OP_ID_OTA_POST_INSTALLATION:
            handleOTAPostnstallation(packet);
            break;
        case OP_ID_CONNECTIVITY_STATUS:
            handleConnectivityStatus(packet);
            break;
        case OP_ID_APP_INSTALL_CONSENT:
            handleAppInstallConsent(packet);
            break;
        case OP_ID_SYNC_SCH_INSTALL_TIME:
            handleSyncSchInstallTime(packet);
            break;
        case OP_ID_BSSID_DISPLAYEDVERSION_SYNC:
            handleBSSIDDisplayedVersionSync(packet);
            break;
        case OP_ID_OTA_URL_INFO:
            handleOTAURLInfo(packet);
            break;
        case OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU:
            handleAssignmentkeytoTargetECU(packet);
            break;
        case OP_ID_OTA_SIGNATURE_CERTIFICATE:
            handleOTASignatureCertificate(packet);
            break;
        case OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION:
            handleOTAWriteInstallationInstruction(packet);
            break;
        case OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO:
            handleOTAAssignmentFileInfo(packet);
            break;
        case OP_ID_USER_OTA_SETTINGS:
            ALOGE("%s, handle event OP_ID_USER_OTA_SETTINGS", __func__);
            handleOTAUserOTASettings(packet);
            break;
        case OP_ID_RVDC_TRANSFER_LOGS_CRC:
            handleTransferLogsCRC(packet);
            break;
        case OP_ID_RVDC_TRANSFER_LOGS_DATA:
            handleRVDCTransferLogsData(packet);
            break;
        case OP_ID_RVDC_LOG_TRANSFER_RETRY:
            handleLogTransferRetry(packet);
            break;
        default:
            ALOGE("%s, unknown operation ID: %hu", __func__, header->operation_id);
            return;
    }

    //ALOGV("%s, received ipcp header : sid: %hu\n", __func__, header->service_id);
    for (uint16_t i = 0; i < len; i++) {
        //ALOGE("%s, %#x", __func__, packet->payload[i]);
    }
}

ipcp_callbacks_t ota_callbacks = {
    .ipcp_received_cb = ota_received_cb,
    .error_cb = ota_error_cb,
};

Ota::Ota() : mCallbackDeathRecipient(new DeathRecipient(this)) {
    //ALOGD("%s", __func__);
    cookie = this;
}

Ota::~Ota() {
    //ALOGD("%s", __func__);
    ipcp_cleanup();
}

sp<Ota> Ota::getOta(void* cookie) {
    //ALOGI("%s", __func__);
    wp<Ota> weak(reinterpret_cast<Ota*>(cookie));
    sp<Ota> ota = weak.promote();
    return ota;
}

void Ota::onFirstRef() {
    //ALOGD("%s", __func__);
}

Return<StatusCode> Ota::init_ota_ipcp() {
    ALOGD("%s", __func__);

    ipcp_transport_conf_t client_config;
    ipcp_stack_err_t error_code;

    init_ota_side(&client_config);
    error_code = ipcp_setup_with_opids(client_config, &ota_callbacks, Connectivity_OperationIDs, 20);

    if (error_code != 0) {
        ALOGE("ota client side setup error: %d", error_code);
        return StatusCode::FAILED;
    } else {
        //ALOGV("ota client side setup success");
        // setupDtcnl();
        return StatusCode::SUCCESS;
    }
}

void init_ota_ipcp_internal() {
    ALOGD("%s", __func__);
    // sp<Ota> ota = Ota::getOta(cookie);

    ipcp_transport_conf_t client_config;
    ipcp_stack_err_t error_code;

    init_ota_side(&client_config);
    error_code = ipcp_setup_with_opids(client_config, &ota_callbacks, Connectivity_OperationIDs, 20);

    if (error_code != 0) {
        ALOGE("ota client side setup error: %d", error_code);
    } else {
        //ALOGV("ota client side setup success");
    }
    // ota->setupDtcnl();
}

Return<StatusCode> Ota::requestOTAAssignment() {
    ALOGI("%s", __func__);

    auto task = []() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1C_OpGeneric_Request OpGeneric_RequestPDU(encodeBuffer);
        if ((stat = OpGeneric_RequestPDU.Encode()) == 0) {
            if (trace) {
                ALOGV("Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }

            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_ASSIGNMENT_SYNC, OP_TYPE_REQUEST,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("%s: ipcp send success", __FUNCTION__);
            }
        } else {
            ALOGE("requestOTAAssignment OpGeneric_RequestPDU encode failed\n");
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::requestSyncSchInstallTime() {
    ALOGI("%s", __func__);

    auto task = []() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpSyncSchInstallTime_Response data;
        data.schInstalldeltatime = 0;
        ASN1C_OpSyncSchInstallTime_Response OpGeneric_RequestPDU(encodeBuffer, data);
		
        if ((stat = OpGeneric_RequestPDU.Encode()) == 0) {
            if (trace) {
                ALOGV("Encoding was successful\n");
                // ALOGV("Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGV("Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGV("requestSyncSchInstallTime OpGeneric_RequestPDU encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_SYNC_SCH_INSTALL_TIME, OP_TYPE_REQUEST,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("requestSyncSchInstallTime ipcp send success");
            }
        } else {
            ALOGE("requestSyncSchInstallTime OpGeneric_RequestPDU encode failed\n");
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setDownloadConsent(const hidl_string& installationorder,
                                           bool downloadconsent) {
    ALOGI("%s", __func__);
    auto task = [installationorder, downloadconsent]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpDownloadConsent_Notification data;
        data.installationorder.uuid = (const char*)installationorder.c_str();
        data.downloadconsent = (OSBOOL)downloadconsent;
        ALOGD("setDownloadConsent data.installationorder.uuid = %s", data.installationorder.uuid);
        ALOGD("setDownloadConsent data.downloadconsent = %d", data.downloadconsent);
        ASN1C_OpDownloadConsent_Notification OpDownloadConsent_Notification(encodeBuffer, data);

        if ((stat = OpDownloadConsent_Notification.Encode()) == 0) {
            if (trace) {
                ALOGD("setDownloadConsent Encoding was successful\n");
                // ALOGD("setDownloadConsent Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGD("setDownloadConsent Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGD("setDownloadConsent encode success");
            len = encodeBuffer.getMsgLen();
            // ALOGD("setDownloadConsent encode success len = %d", len);
            content = (char*)encodeBuffer.getMsgPtr();
            // ALOGD("setDownloadConsent encode success content = %s", content);
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_DOWNLOAD_CONSENT, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGD("setDownloadConsent ipcp send success");
            }
        } else {
            ALOGE("setDownloadConsent encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);

    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setUserOtaSettings(const OpOTAUserOtaSettingsHal& opOTAUserOtaSettingsHal) {
    ALOGI("%s", __func__);
    auto task = [opOTAUserOtaSettingsHal]() {
       const char* content = NULL;
       int stat, len;
       bool trace = FALSE;
       ipcp_stack_err_t err;
       ASN1PEREncodeBuffer encodeBuffer(false);
       ASN1T_OpUserOTASettings_Notification data;
       data.userOTASetting.otasetting = (OSBOOL)opOTAUserOtaSettingsHal.otasetting;
       data.userOTASetting.autosync = (OSBOOL)opOTAUserOtaSettingsHal.autosync;
       data.userOTASetting.autodownload = (OSBOOL)opOTAUserOtaSettingsHal.autodownload;
       data.userOTASetting.autoinstallation = (OSBOOL)opOTAUserOtaSettingsHal.autoinstallation;
       data.userOTASetting.autoinstallationtime = (const char*)opOTAUserOtaSettingsHal.autoinstallationtime.c_str();;

       ALOGD("setUserOtaSettings data.userOTASetting.otasetting = %d", data.userOTASetting.otasetting);
       ALOGD("setUserOtaSettings data.userOTASetting.autosync = %d", data.userOTASetting.autosync);
       ALOGD("setUserOtaSettings data.userOTASetting.autodownload = %d", data.userOTASetting.autodownload);
       ALOGD("setUserOtaSettings data.userOTASetting.autoinstallation = %d", data.userOTASetting.autoinstallation);
       ALOGD("setUserOtaSettings data.userOTASetting.autoinstallationtime = %s", data.userOTASetting.autoinstallationtime);

       ASN1C_OpUserOTASettings_Notification OpUserOTASettings_Notification(
           encodeBuffer, data);
       if ((stat = OpUserOTASettings_Notification.Encode()) == 0) {
           if (trace) {
               ALOGV("setUserOtaSettings Encoding was successful\n");
               ALOGV("setUserOtaSettings Hex dump of encoded record:\n");
               encodeBuffer.hexDump();
               ALOGV("setUserOtaSettings Binary dump:\n");
               encodeBuffer.binDump("Data");
           }
           ALOGV("OpUserOTASettings_Notification encode success");
           len = encodeBuffer.getMsgLen();
           content = (char*)encodeBuffer.getMsgPtr();
           ipcp_packet_t* packet =
               build_ipcp_packet(SERVICE_ID, OP_ID_USER_OTA_SETTINGS, OP_TYPE_NOTIFICATION,
                                 IPCP_DATA_ENCODED, (void*)content, len);
           std::string otasetting_status = std::to_string(data.userOTASetting.otasetting);
           std::string autosync_status = std::to_string(data.userOTASetting.autosync);
           std::string autodownload_status = std::to_string(data.userOTASetting.autodownload);
           std::string autoinstall_status = std::to_string(data.userOTASetting.autoinstallation);
           android::base::SetProperty(OTA_SETTING, otasetting_status);
           android::base::SetProperty(OTA_AUTO_SYNC, autosync_status);
           android::base::SetProperty(OTA_AUTO_DOWNLOAD, autodownload_status);
           android::base::SetProperty(OTA_AUTO_INSTALL, autoinstall_status);
           if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
               ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
           } else {
               ALOGV("setUserOtaSettings ipcp send success");
           }
       } else {
           ALOGE("OpUserOTASettings_Notification encode failed\n");
           encodeBuffer.printErrorInfo();
       }
   };
   mThread.schedule(task, gDefaultDelay.common);
   return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildUserOtaSettingsTest(const OpOTAUserOtaSettingsHal& opOTAUserOtaSettingsHal) {
    ALOGI("%s", __func__);
    auto task = [opOTAUserOtaSettingsHal]() {
       const char* content = NULL;
       int stat, len;
       bool trace = FALSE;
       ipcp_stack_err_t err;
       ASN1PEREncodeBuffer encodeBuffer(false);
       ASN1T_OpUserOTASettings_Notification data;
       data.userOTASetting.otasetting = (OSBOOL)opOTAUserOtaSettingsHal.otasetting;
       data.userOTASetting.autosync = (OSBOOL)opOTAUserOtaSettingsHal.autosync;
       data.userOTASetting.autodownload = (OSBOOL)opOTAUserOtaSettingsHal.autodownload;
       data.userOTASetting.autoinstallation = (OSBOOL)opOTAUserOtaSettingsHal.autoinstallation;
	   data.userOTASetting.autoinstallationtime = (const char*)opOTAUserOtaSettingsHal.autoinstallationtime.c_str();;

       ALOGD("buildUserOtaSettingsTest data.userOTASetting.otasetting = %d", data.userOTASetting.otasetting);
       ALOGD("buildUserOtaSettingsTest data.userOTASetting.autosync = %d", data.userOTASetting.autosync);
       ALOGD("buildUserOtaSettingsTest data.userOTASetting.autodownload = %d", data.userOTASetting.autodownload);
       ALOGD("buildUserOtaSettingsTest data.userOTASetting.autoinstallation = %d", data.userOTASetting.autoinstallation);
       ALOGD("buildUserOtaSettingsTest data.userOTASetting.autoinstallationtime = %s", data.userOTASetting.autoinstallationtime);

       ASN1C_OpUserOTASettings_Notification opUserOTASettings_Notification(
           encodeBuffer, data);
       if ((stat = opUserOTASettings_Notification.Encode()) == 0) {
           if (trace) {
               ALOGV("buildUserOtaSettingsTest Encoding was successful\n");
               ALOGV("buildUserOtaSettingsTest Hex dump of encoded record:\n");
               encodeBuffer.hexDump();
               ALOGV("buildUserOtaSettingsTest Binary dump:\n");
               encodeBuffer.binDump("Data");
           }
           ALOGV("OpUserOTASettings_Notification encode success");
           len = encodeBuffer.getMsgLen();
           content = (char*)encodeBuffer.getMsgPtr();
           ipcp_packet_t* packet =
               build_ipcp_packet(SERVICE_ID, OP_ID_USER_OTA_SETTINGS, OP_TYPE_NOTIFICATION,
                                 IPCP_DATA_ENCODED, (void*)content, len);
           std::string otasetting_status = std::to_string(data.userOTASetting.otasetting);
           std::string autosync_status = std::to_string(data.userOTASetting.autosync);
           std::string autodownload_status = std::to_string(data.userOTASetting.autodownload);
           std::string autoinstall_status = std::to_string(data.userOTASetting.autoinstallation);
           android::base::SetProperty(OTA_SETTING, otasetting_status);
           android::base::SetProperty(OTA_AUTO_SYNC, autosync_status);
           android::base::SetProperty(OTA_AUTO_DOWNLOAD, autodownload_status);
           android::base::SetProperty(OTA_AUTO_INSTALL, autoinstall_status);
           if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
               ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
           } else {
               ALOGV("buildUserOtaSettingsTest ipcp send success");
           }
       } else {
           ALOGE("OpUserOTASettings_SetRequest_NoReturn encode failed\n");
           encodeBuffer.printErrorInfo();
       }
   };
   mThread.schedule(task, gDefaultDelay.common);
   return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setInstallationConsent(const hidl_string& installationorder,
                                               InstallationConsent installationConsent,
                                               int deltatime) {
    ALOGI("%s", __func__);
    auto task = [installationorder, installationConsent, deltatime]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpInstallationConsent_Notification data;
        data.m.deltatimePresent = 1;
        data.installationorder.uuid = (char*)installationorder.c_str();
        int installationconsent = static_cast<int>(installationConsent);
        data.installationconsent = InstallationConsent_Installationconsent::Root(installationconsent);
        data.deltatime = (OSUINT32)deltatime;
        ALOGD("setInstallationConsent data.installationorder.uuid = %s",
              data.installationorder.uuid);
        ALOGD("setInstallationConsent data.installationconsent = %d", data.installationconsent);
        ALOGD("setInstallationConsent data.deltatime = %d", data.deltatime);
        ASN1C_OpInstallationConsent_Notification OpInstallationConsent_Notification(encodeBuffer,
                                                                                    data);
        if ((stat = OpInstallationConsent_Notification.Encode()) == 0) {
            if (trace) {
                ALOGV("setInstallationConsent Encoding was successful\n");
                // ALOGV("setInstallationConsent Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGV("setInstallationConsent Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGV("OpInstallationConsent_Notification encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_INSTALLATION_CONSENT, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("setInstallationConsent ipcp send success");
            }
        } else {
            ALOGE("OpInstallationConsent_Notification encode failed\n");
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setOTAHMILanguageSettings(Languages languages) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);
    auto task = [languages]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAHMILanguageSettings_Notification data;
        int language = static_cast<int>(languages);
        //转换方法待验证
        data.languagesetting = LanguageSetting::Root(language);
        ASN1C_OpOTAHMILanguageSettings_Notification OpOTAHMILanguageSettings_Notification(
            encodeBuffer, data);
        if ((stat = OpOTAHMILanguageSettings_Notification.Encode()) == 0) {
            if (trace) {
                ALOGV("setOTAHMILanguageSettings Encoding was successful\n");
                // ALOGV("setOTAHMILanguageSettings Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGV("setOTAHMILanguageSettings Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGV("OpOTAHMILanguageSettings_Notification encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_HMI_LANGUAGESETTINGS, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("setOTAHMILanguageSettings ipcp send success");
            }
        } else {
            ALOGE("OpOTAHMILanguageSettings_Notification encode failed\n");
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::requestOTAConnectivitySts() {
    ALOGI("%s", __func__);

    auto task = []() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1C_OpGeneric_Request OpGeneric_RequestPDU(encodeBuffer);
        if ((stat = OpGeneric_RequestPDU.Encode()) == 0) {
            if (trace) {
                ALOGV("Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t *packet = build_ipcp_packet(SERVICE_ID, OP_ID_CONNECTIVITY_STATUS,
                        OP_TYPE_REQUEST, IPCP_DATA_ENCODED,(void *)content, len);
            
            if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("requestOTAConnectivitySts ipcp send success");
            }

        } else {
            ALOGE("requestOTAConnectivitySts OpGeneric_RequestPDU encode failed\n");
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::requestBSSIDDisplayedVersionSync() {
    ALOGI("%s", __func__);

    auto task = []() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1C_OpGeneric_Request OpGeneric_RequestPDU(encodeBuffer);
        if ((stat = OpGeneric_RequestPDU.Encode()) == 0) {
            if (trace) {
                ALOGV("Encoding was successful\n");
                // ALOGV("Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGV("Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            //ALOGV("requestBSSIDDisplayedVersionSync OpGeneric_RequestPDU encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_BSSID_DISPLAYEDVERSION_SYNC, OP_TYPE_REQUEST,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_vgm_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("requestBSSIDDisplayedVersionSync ipcp send success");
            }
        } else {
            ALOGE("requestBSSIDDisplayedVersionSync OpGeneric_RequestPDU encode failed\n");
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setOTAInstallationRegretTimeOut(const OpOTAInstallationRegretTimeOutHal& opOTAInstallationRegretTimeOutHal) {
    ALOGI("%s", __func__);
    auto task = [opOTAInstallationRegretTimeOutHal]() {
       const char* content = NULL;
       int stat, len;
       bool trace = FALSE;
       ipcp_stack_err_t err;
       ASN1PEREncodeBuffer encodeBuffer(false);
       ASN1T_OpOTAInstallationRegretTimeOut_Notification data;
       data.m.reasonPresent = 1;
       data.installationorder.uuid = (const char*)opOTAInstallationRegretTimeOutHal.installationorder.c_str();
       data.isotimestamp.timestamp = opOTAInstallationRegretTimeOutHal.isotimestamp.c_str();
       data.newstatus = opOTAInstallationRegretTimeOutHal.newstatus.c_str();
       data.reason = opOTAInstallationRegretTimeOutHal.reason.c_str();

       ALOGD("setOTAInstallationRegretTimeOut data.installationorder = %s", data.installationorder.uuid);
       ALOGD("setOTAInstallationRegretTimeOut data.isotimestamp = %s", data.isotimestamp.timestamp);
       ALOGD("setOTAInstallationRegretTimeOut data.newstatus = %s", data.newstatus);
       ALOGD("setOTAInstallationRegretTimeOut data.reason = %s", data.reason);

       ASN1C_OpOTAInstallationRegretTimeOut_Notification OpOTAInstallationRegretTimeOut_Notification(
           encodeBuffer, data);
       if ((stat = OpOTAInstallationRegretTimeOut_Notification.Encode()) == 0) {
           if (trace) {
               ALOGV("setOTAInstallationRegretTimeOut Encoding was successful\n");
               ALOGV("setOTAInstallationRegretTimeOut Hex dump of encoded record:\n");
               encodeBuffer.hexDump();
               ALOGV("setOTAInstallationRegretTimeOut Binary dump:\n");
               encodeBuffer.binDump("Data");
           }
           ALOGV("OpOTAInstallationRegretTimeOut_Notification encode success");
           len = encodeBuffer.getMsgLen();
           content = (char*)encodeBuffer.getMsgPtr();
           ipcp_packet_t* packet =
               build_ipcp_packet(SERVICE_ID, OP_ID_OTA_INSTALLATION_REGRET_TIMEOUT, OP_TYPE_NOTIFICATION,
                                 IPCP_DATA_ENCODED, (void*)content, len);
           if ((err = ipcp_send(peer_ota_vgm_server, packet)) != STACK_SEND_MSG_SUCCESS) {
               ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
           } else {
               ALOGV("setOTAInstallationRegretTimeOut ipcp send success");
           }
       } else {
           ALOGE("OpOTAInstallationRegretTimeOut_Notification encode failed\n");
           encodeBuffer.printErrorInfo();
       }
   };
   mThread.schedule(task, gDefaultDelay.common);
   return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setOTADownloadStatusHal( const OpOTADownloadStatusHal& opOTADownloadStatusHal){
    ALOGI("%s", __func__);
    auto task = [opOTADownloadStatusHal]() {
       const char* content = NULL;
       int stat, len;
       bool trace = FALSE;
       ipcp_stack_err_t err;
       ASN1PEREncodeBuffer encodeBuffer(false);
       ASN1T_OpOTADownloadStatus_Notification data;
       data.m.downloadsizePresent = 1;
       data.m.newstatusPresent = 1;
       data.m.reasonPresent = 1;
       data.installationorder.uuid = (const char*)opOTADownloadStatusHal.installationorder.c_str();
       data.isotimestamp.timestamp = opOTADownloadStatusHal.isotimestamp.c_str();
       data.downloadsize = opOTADownloadStatusHal.downloadsize;
       data.newstatus = opOTADownloadStatusHal.newstatus.c_str();
       data.reason = opOTADownloadStatusHal.reason.c_str();

       ALOGD("setOTADownloadStatusHal data.installationorder = %s", data.installationorder.uuid);
       ALOGD("------------------------------- data.isotimestamp = %s", data.isotimestamp.timestamp);
       ALOGD("------------------------------- data.downloadsize = %d", data.downloadsize);
       ALOGD("------------------------------- data.newstatus = %s", data.newstatus);
       ALOGD("------------------------------- data.reason = %s", data.reason);

       ASN1C_OpOTADownloadStatus_Notification OpOTADownloadStatus_Notification(
           encodeBuffer, data);
       if ((stat = OpOTADownloadStatus_Notification.Encode()) == 0) {
           if (trace) {
               ALOGV("setOTADownloadStatusHal Encoding was successful\n");
               ALOGV("setOTADownloadStatusHal Hex dump of encoded record:\n");
               encodeBuffer.hexDump();
               ALOGV("setOTADownloadStatusHal Binary dump:\n");
               encodeBuffer.binDump("Data");
           }
           ALOGV("setOTADownloadStatusHal encode success");
           len = encodeBuffer.getMsgLen();
           content = (char*)encodeBuffer.getMsgPtr();
           ipcp_packet_t* packet =
               build_ipcp_packet(SERVICE_ID, OP_ID_OTA_DOWNLOAD_STATUS, OP_TYPE_NOTIFICATION,
                                 IPCP_DATA_ENCODED, (void*)content, len);
           if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
               ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
           } else {
               ALOGV("setOTADownloadStatusHal ipcp send success");
           }
       } else {
           ALOGE("setOTADownloadStatusHal encode failed\n");
           encodeBuffer.printErrorInfo();
       }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}


Return<StatusCode> Ota::setAssignmentkeytoTargetECUResHal( const OpAssignmentkeytoTargetECUHal& opAssignmentkeytoTargetECUHal){
ALOGI("%s", __func__);
    auto task = [opAssignmentkeytoTargetECUHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAAssignmentkeytoTargetECU_Response data;
        data.m.fileSizePresent = 1;
        data.status = (char*)opAssignmentkeytoTargetECUHal.status.c_str();
        data.fileSize = opAssignmentkeytoTargetECUHal.fileSize;

        ALOGD("setAssignmentkeytoTargetECUResHal data.fileSize = %d", data.fileSize);
        ALOGD("setAssignmentkeytoTargetECUResHal data.status = %s", data.status);

        ASN1C_OpOTAAssignmentkeytoTargetECU_Response opOTAAssignmentkeytoTargetECU_Response(encodeBuffer, data);
        if ((stat = opOTAAssignmentkeytoTargetECU_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("setAssignmentkeytoTargetECUResHal Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_response(SERVICE_ID, OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU, mAssignmentkeyHandleId,
                                  IPCP_DATA_ENCODED, (void*)content, len);

            if (0 == testMode) {
                if ((err = ipcp_send(peer_ota_vgm_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setAssignmentkeytoTargetECUResHal ipcp send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setAssignmentkeytoTargetECUResHal ipcp test send success");
                }
            }

        } else {
            ALOGE("setAssignmentkeytoTargetECUResHal encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setOTAExceptionReportsHal( const OpOTAExceptionReportsHal& opOTAExceptionReportsHal){
    ALOGI("%s", __func__);
    auto task = [opOTAExceptionReportsHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAExceptionReports_Notification data;
        ASN1T_ExceptionReport report_1;

        report_1.m.datablockPresent = 1;
        report_1.m.ecuaddressPresent = 1;
        report_1.m.filenamePresent = 1;
        report_1.m.keynamePresent = 1;
        report_1.m.keyvaluePresent = 1;
        report_1.exceptionmessage.m.actionPresent = 1;
        report_1.exceptionmessage.m.activityPresent = 1;
        report_1.exceptionmessage.m.logParamsPresent = 1;

        report_1.exceptionuniquesourceid.t = 2;
        report_1.exceptionuniquesourceid.u.installationorder = new ASN1T_OTAExceptionReports_UUID;
        report_1.exceptionuniquesourceid.u.installationorder->uuid = (const char*)opOTAExceptionReportsHal.installationorder.c_str();
        report_1.isotimestamp.timestamp = (const char*)opOTAExceptionReportsHal.isotimestamp.c_str();
        report_1.issuerid = (const char*)opOTAExceptionReportsHal.issuerid.c_str();
        report_1.filename.name = (OSUTF8CHAR*)opOTAExceptionReportsHal.filename.c_str();
        report_1.ecuaddress.addr.numocts = 2;
        report_1.ecuaddress.addr.data[0] = 0x12;
        report_1.ecuaddress.addr.data[1] = 0x02;
        report_1.exceptionmessage.exception = (const char*)opOTAExceptionReportsHal.exception.c_str();
        report_1.exceptionmessage.logParams = (const char*)opOTAExceptionReportsHal.logParams.c_str();
        
        //unuse data
        report_1.exceptionuniquesourceid.u.clientversion = new ASN1T_OTAExceptionReports_UUID; 
        report_1.exceptionuniquesourceid.u.clientversion->uuid = (const char*)opOTAExceptionReportsHal.installationorder.c_str();
        report_1.keyname.keyname.numocts = 2;
        report_1.keyname.keyname.data[0] = 0x12;
        report_1.keyname.keyname.data[1] = 0x02;
        report_1.datablock.blockNumber.numocts = 2;
        report_1.datablock.blockNumber.data[0] = 0x12;
        report_1.datablock.blockNumber.data[1] = 0x02;
        report_1.exceptionmessage.action =  (const char*)opOTAExceptionReportsHal.logParams.c_str();
        report_1.exceptionmessage.activity =  (const char*)opOTAExceptionReportsHal.logParams.c_str();
        
        ASN1C_OpOTAExceptionReports_Notification_exceptionreports   exceptionreports(data.exceptionreports);
        exceptionreports.Append(&report_1);

        ALOGD("setOTAExceptionReportsHal installationorder = %s", report_1.exceptionuniquesourceid.u.installationorder->uuid);
        ALOGD("------------------------------- clientversion = %s", report_1.exceptionuniquesourceid.u.clientversion->uuid);
        ALOGD("------------------------------- isotimestamp = %s", report_1.isotimestamp.timestamp);
        ALOGD("------------------------------- issuerid = %s", report_1.issuerid);
        ALOGD("------------------------------- filename.name = %s", report_1.filename.name);
        ALOGD("------------------------------- exceptionmessage.exception = %s", report_1.exceptionmessage.exception);
        ALOGD("------------------------------- exceptionmessage.logParams = %s", report_1.exceptionmessage.logParams);

        ASN1C_OpOTAExceptionReports_Notification opOTAExceptionReports_Notification(encodeBuffer, data);
        if ((stat = opOTAExceptionReports_Notification.Encode()) == 0) {
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();

            ipcp_packet_t* packet = build_ipcp_packet(SERVICE_ID, OP_ID_OTA_EXCEPTION_REPORTS, OP_TYPE_NOTIFICATION,
                                    IPCP_DATA_ENCODED, (void*)content, len);

            if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("setOTAExceptionReportsHal ipcp send success");
            }
        } else {
            ALOGE("setOTAExceptionReportsHal encode failed\n");
            encodeBuffer.printErrorInfo();
        }

        delete report_1.exceptionuniquesourceid.u.installationorder;
        report_1.exceptionuniquesourceid.u.installationorder = nullptr;
        delete report_1.exceptionuniquesourceid.u.clientversion;
        report_1.exceptionuniquesourceid.u.clientversion = nullptr;
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setOTAURLInfoResHal(const hidl_string& status) {
    ALOGI("%s", __func__);
    auto task = [status]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAURLInfo_Response data;
        data.status = (const char*)status.c_str();
        ALOGD("setOTAURLInfoResHal data.status = %s", data.status);
        ASN1C_OpOTAURLInfo_Response opOTAURLInfo_Response(encodeBuffer, data);

        if ((stat = opOTAURLInfo_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("ASN1C_OpOTAURLInfo_Response Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_response(SERVICE_ID, OP_ID_OTA_URL_INFO, mUrlInfoHandledId,
                                  IPCP_DATA_ENCODED, (void*)content, len);

            if (0 == testMode) {
                if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setOTAURLInfoResHal ipcp send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setOTAURLInfoResHal ipcp test send success");
                }
            }


        } else {
            ALOGE("setOTAURLInfoResHal encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setSignatureCertificateResHal(const hidl_string& chkResponse) {
    ALOGI("%s", __func__);
    auto task = [chkResponse]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTASignatureCertificate_Response data;
        data.oTASignatureCertificateResp = (char*)chkResponse.c_str();
        ALOGD("setSignatureCertificateResHal data.status = %s", data.oTASignatureCertificateResp);
        ASN1C_OpOTASignatureCertificate_Response opOTASignatureCertificate_Response(encodeBuffer, data);

        if ((stat = opOTASignatureCertificate_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("opOTASignatureCertificate_Response Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_response(SERVICE_ID, OP_ID_OTA_SIGNATURE_CERTIFICATE, mSignatureCertificateHandleId,
                                  IPCP_DATA_ENCODED, (void*)content, len);

            if (0 == testMode) {
                if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opOTASignatureCertificate_Response ipcp send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opOTASignatureCertificate_Response ipcp test send success");
                }
            }
            

        } else {
            ALOGE("opOTASignatureCertificate_Response encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}


Return<StatusCode> Ota::setWriteInstallationInstructionResHal(const hidl_string& chkResponse) {
    ALOGI("%s", __func__);
    auto task = [chkResponse]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAWriteInstallationInstructions_Response data;
        data.status = (const char*)chkResponse.c_str();
        ALOGD("setWriteInstallationInstructionResHal data.status = %s", data.status);
        ASN1C_OpOTAWriteInstallationInstructions_Response OpOTAWriteInstallationInstructions_Response(encodeBuffer, data);

        if ((stat = OpOTAWriteInstallationInstructions_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("setWriteInstallationInstructionResHal Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_response(SERVICE_ID, OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION, mWriteInstallationInstructionHandleId,
                                  IPCP_DATA_ENCODED, (void*)content, len);

            if ( 0 == testMode) {
                if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setWriteInstallationInstructionResHal ipcp send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setWriteInstallationInstructionResHal ipcp test send success");
                }
            }
            

        } else {
            ALOGE("setWriteInstallationInstructionResHal encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}


Return<StatusCode> Ota::setAssignmentFileInfoResHal(const hidl_string& chkResponse) {
    ALOGI("%s", __func__);
    auto task = [chkResponse]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTASetAssignmentFileInfo_Response data;
        data.status = (char*)chkResponse.c_str();
        ALOGD("setAssignmentFileInfoResHal data.status = %s", data.status);
        ASN1C_OpOTASetAssignmentFileInfo_Response opOTASetAssignmentFileInfo_Response(encodeBuffer, data);

        if ((stat = opOTASetAssignmentFileInfo_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("setAssignmentFileInfoResHal Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_response(SERVICE_ID, OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO, mFileInfoHandleId,
                                  IPCP_DATA_ENCODED, (void*)content, len);

            if (0 == testMode) {
                if ((err = ipcp_send(peer_ota_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setAssignmentFileInfoResHal ipcp  send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("setAssignmentFileInfoResHal ipcp test send success");
                }
            }
            
        } else {
            ALOGE("setAssignmentFileInfoResHal encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setRVDCTransferLogsCRCResHal(const hidl_string& name, const hidl_string& status) {
    ALOGI("%s", __func__);
    auto task = [name, status]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpRVDCTransferLogsCRC_Response data;
        data.logname.name = (OSUTF8CHAR*)name.c_str();
        data.status = (char*)status.c_str();
        ALOGD("setRVDCTransferLogsCRCResHal data.logname = %s", data.logname.name);
        ALOGD("setRVDCTransferLogsCRCResHal data.status = %s", data.status);
        ASN1C_OpRVDCTransferLogsCRC_Response opTransferLogsCRC_Response(encodeBuffer, data);

        if ((stat = opTransferLogsCRC_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("opTransferLogsCRC_Response Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet = build_ipcp_response(SERVICE_ID, OP_ID_RVDC_TRANSFER_LOGS_CRC,
                                     mSignatureCertificateHandleId, IPCP_DATA_ENCODED, (void*)content, len);

            if (0 == testMode) {
                if ((err = ipcp_send(peer_ota_vgm_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opTransferLogsCRC_Response ipcp send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opTransferLogsCRC_Response ipcp test send success");
                }
            }
        } else {
            ALOGE("opTransferLogsCRC_Response encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setRVDCVerificationCRCStatusHal(const hidl_string& name, bool verificationok) {
    ALOGI("%s", __func__);
    auto task = [name, verificationok]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpRVDCVerificationCRCStatus_Notification data;
        data.logname.name = (OSUTF8CHAR*)name.c_str();
        data.verificationok = (OSBOOL)verificationok;
        ALOGD("setRVDCVerificationCRCStatusHal data.logname = %s", data.logname.name);
        ALOGD("setRVDCVerificationCRCStatusHal data.verificationok = %d", data.verificationok);

        ASN1C_OpRVDCVerificationCRCStatus_Notification opVerificationCRC_Response(encodeBuffer, data);
        if ((stat = opVerificationCRC_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("opVerificationCRC_Response Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet = build_ipcp_response(SERVICE_ID, OP_ID_RVDC_VERIFICATION_CRC_STATUS,
                                     mSignatureCertificateHandleId, IPCP_DATA_ENCODED, (void*)content, len);

            if (0 == testMode) {
                if ((err = ipcp_send(peer_ota_vgm_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opVerificationCRC_Response ipcp send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opVerificationCRC_Response ipcp test send success");
                }
            }
        } else {
            ALOGE("opVerificationCRC_Response encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setRVDCTransLogDataResHal(const TransRVDCLogDataResponse& response) {
    ALOGI("%s", __func__);
    auto task = [response]() {
        unsigned char content[MAX_BUF_LEN] = {0};
        int stat, len;
        ipcp_stack_err_t err;
        content[0] = (response.chunknumber >> 24) & 0xFF;
        content[1] = (response.chunknumber >> 16) & 0xFF;
        content[2] = (response.chunknumber >> 8) & 0xFF;
        content[3] = response.chunknumber & 0xFF;
        int logStatus = static_cast<int>(response.mTranRVDCLogStatus);
        content[4] = logStatus & 0xFF;
        len = sizeof(content);
        ALOGD("setRVDCTransLogDataResHal data.chunknumber = %d", response.chunknumber);
        ALOGD("setRVDCTransLogDataResHal data.response = %d", response.mTranRVDCLogStatus);

        ipcp_packet_t* packet = build_ipcp_response(SERVICE_ID, OP_ID_RVDC_TRANSFER_LOGS_DATA,
                                     mSignatureCertificateHandleId, IPCP_DATA_NORMAL, (void*)content, len);

        if (0 == testMode) {
            if ((err = ipcp_send(peer_ota_vgm_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGD("OP_ID_RVDC_TRANSFER_LOGS_DATA ipcp send success");
            }
        } else {
           if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
              ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
           } else {
               ALOGD("OP_ID_RVDC_TRANSFER_LOGS_DATA ipcp test send success");
           }
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::setRVDCLogInterruptedDataTransferRetryResHal(int filesize) {
    ALOGI("%s", __func__);
    auto task = [filesize]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpRVDCLogInterruptedDataTransferRetry_Response data;
        data.filesize = (OSUINT32)filesize;
        ALOGD("setRVDCLogInterruptedDataTransferRetryResHal data.filesize = %d", data.filesize);
        ASN1C_OpRVDCLogInterruptedDataTransferRetry_Response opLogTransferRetry_Response(encodeBuffer, data);

        if ((stat = opLogTransferRetry_Response.Encode()) == 0) {
            if (trace) {
                ALOGD("opLogTransferRetry_Response Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet = build_ipcp_response(SERVICE_ID, OP_ID_RVDC_LOG_TRANSFER_RETRY,
                                    mSignatureCertificateHandleId, IPCP_DATA_ENCODED, (void*)content, len);
            if (0 == testMode) {
                if ((err = ipcp_send(peer_ota_vgm_server, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opLogTransferRetry_Response ipcp send success");
                }
            } else {
                if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                    ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
                } else {
                    ALOGD("opLogTransferRetry_Response ipcp test send success");
                }
            }
        } else {
            ALOGE("opLogTransferRetry_Response encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::subscribe(const ::android::sp<IOtaClientCallback>& callback) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);
    StatusCode ret = StatusCode::FAILED;
    auto res = callback->linkToDeath(mCallbackDeathRecipient, 0);
    if (!res.isOk()) {  // Client is already dead?
        ALOGW("%s failed to link to death, client %p, err: %s", __func__, callback.get(),
              res.description().c_str());
    }

    if (mCallback == NULL) {
        mCallback = callback;
        ret = StatusCode::SUCCESS;
    } else {
        ALOGE("subscribe failed! do not unsubscribe!");
    }

    return ret;
}

Return<StatusCode> Ota::unsubscribe(const ::android::sp<IOtaClientCallback>& callback) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);
    StatusCode ret = StatusCode::FAILED;
    auto res = callback->unlinkToDeath(mCallbackDeathRecipient);
    if (!res.isOk()) {
        ALOGW("%s failed to unlink to death, client: %p, err: %s", __func__, callback.get(),
              res.description().c_str());
    }
    if (mCallback != NULL) {
        mCallback = NULL;
        ret = StatusCode::SUCCESS;
    } else {
        ALOGE("already unsubscribe!");
    }
    return ret;
}

sp<IOtaClientCallback> Ota::getCallback() {
    if (mCallback != NULL) {
        return mCallback;
    } else {
        return NULL;
    }
}

//----------------------------------------------------------------
//------------------------ OTA TEST START ------------------------
ota_callback Ota::gOtaCallback = NULL;

Return<StatusCode> Ota::init_ota_ipcp_test() {
    ALOGD("%s", __func__);

    ipcp_transport_conf_t client_config;
    ipcp_stack_err_t error_code;

    init_ota_side_test(&client_config);
    error_code = ipcp_setup_with_opids(client_config, &ota_callbacks, Connectivity_OperationIDs, 20);

    if (error_code != 0) {
        ALOGE("ota client side setup error: %d", error_code);
        return StatusCode::FAILED;
    } else {
        ALOGV("ota client side setup success");
        return StatusCode::SUCCESS;
    }
}

Return<StatusCode> Ota::buildOTAHMILanguageSettingsTest(Languages languages) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);
    auto task = [languages]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAHMILanguageSettings_Notification data;

        int language = static_cast<int>(languages);
        data.languagesetting = LanguageSetting::Root(language);

        ASN1C_OpOTAHMILanguageSettings_Notification OpOTAHMILanguageSettings_Notification(
            encodeBuffer, data);

        if ((stat = OpOTAHMILanguageSettings_Notification.Encode()) == 0) {
            if (trace) {
                ALOGV("buildOTAHMILanguageSettingsTest Encoding was successful\n");
                //ALOGV("buildOTAHMILanguageSettingsTest Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                //ALOGV("buildOTAHMILanguageSettingsTest Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGV("buildOTAHMILanguageSettingsTest encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_HMI_LANGUAGESETTINGS, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildOTAHMILanguageSettingsTest ipcp send success");
            }
        } else {
            ALOGE("buildOTAHMILanguageSettingsTest encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildOTAConnectivityStsTest(const ConnectivityStsHal& conSts) {
    ALOGI("%s", __func__);
    auto task = [conSts]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpConnectivityStatus_Response data;
        data.connectionStatus = (OSBOOL)conSts.connectionStatus;

        ALOGD("buildOTAConnectivityStsTest data.connectionStatus = %d", data.connectionStatus);
        ASN1C_OpConnectivityStatus_Response OpConnectivityStatus_Response(encodeBuffer, data);
        if ((stat = OpConnectivityStatus_Response.Encode()) == 0) {
            ALOGD("buildOTAConnectivityStsTest encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_CONNECTIVITY_STATUS, OP_TYPE_RESPONSE,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGD("buildOTAConnectivityStsTest ipcp send success");
            }
        } else {
            ALOGE("buildOTAConnectivityStsTest encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildDownloadProgressNotificationTest(DownloadProgress progress) {
    ALOGI("%s", __func__);
    auto task = [progress]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTADownloadprogress_NotificationCyclic data;
        int progressdata = static_cast<int>(progress);
        data.progressbar = progressdata;
        data.installationorder.uuid = "ffffffff-6149-9428-d686-ac0001fdcc8a";

        ALOGD("buildDownloadProgressNotificationTest progressbar = %d", progress);
        ALOGD("buildDownloadProgressNotificationTest data.installationorder.uuid = %s", data.installationorder.uuid);

        ASN1C_OpOTADownloadprogress_NotificationCyclic OpOTADownloadprogress_Notification(encodeBuffer, data);
        if ((stat = OpOTADownloadprogress_Notification.Encode()) == 0) {
            ALOGD("buildDownloadProgressNotificationTest encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_DOWNLOAD_PROGRESS, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGD("buildDownloadProgressNotificationTest ipcp send success");
            }
        } else {
            ALOGE("buildDownloadProgressNotificationTest encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}


Return<StatusCode> Ota::buildOTAAPPInstallationConsentTest(const APPInstallationConsentHal& appInsConsent) {
    ALOGI("%s", __func__);
    auto task = [appInsConsent]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpAPPInstallationConsent_Notification data;
        data.m.deltatimePresent = 1; 
        data.installationorder.uuid = (const char*)appInsConsent.installationorder.c_str();
        data.appinstallationconsent = Appinstallationconsent::Root(appInsConsent.appinstallationconsent);
        data.deltatime = appInsConsent.deltatime;

        ALOGD("buildOTAAPPInstallationConsentTest data.installationorder.uuid = %s", data.installationorder.uuid);
        ALOGD("buildOTAAPPInstallationConsentTest data.appinstallationconsent = %d", data.appinstallationconsent);
        ALOGD("buildOTAAPPInstallationConsentTest data.deltatime = %d", data.deltatime);
        ASN1C_OpAPPInstallationConsent_Notification ASN1C_OpAPPInstallationConsent_Notification(encodeBuffer, data);
        if ((stat = ASN1C_OpAPPInstallationConsent_Notification.Encode()) == 0) {
            ALOGD("buildOTAAPPInstallationConsentTest encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_APP_INSTALL_CONSENT, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGD("buildOTAAPPInstallationConsentTest ipcp send success");
            }
        } else {
            ALOGE("buildOTAAPPInstallationConsentTest encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildOTASyncSchInstallTimeTest(const SyncSchInstallTimeHal& syncInsTime) {
    ALOGI("%s", __func__);
    auto task = [syncInsTime]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpSyncSchInstallTime_Response data;
        data.schInstalldeltatime = syncInsTime.schInstalldeltatime;

        ALOGD("buildOTASyncSchInstallTimeTest data.schInstalldeltatime = %d", data.schInstalldeltatime);
        ASN1C_OpSyncSchInstallTime_Response ASN1C_OpSyncSchInstallTime_Response(encodeBuffer, data);
        if ((stat = ASN1C_OpSyncSchInstallTime_Response.Encode()) == 0) {
            ALOGD("buildOTASyncSchInstallTimeTest encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_SYNC_SCH_INSTALL_TIME, OP_TYPE_RESPONSE,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGD("buildOTASyncSchInstallTimeTest ipcp send success");
            }
        } else {
            ALOGE("buildOTASyncSchInstallTimeTest encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildInstallationConsentTest(const hidl_string& installationorder,
                                                     InstallationConsent installationConsent,
                                                     int deltatime) {
    ALOGI("%s", __func__);
    auto task = [installationorder, installationConsent, deltatime]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpInstallationConsent_Notification data;
        data.m.deltatimePresent = 1;
        data.installationorder.uuid = (const char*)installationorder.c_str();
        data.installationconsent = InstallationConsent_Installationconsent::Root(installationConsent);
        data.deltatime = (OSUINT32)deltatime;

        ALOGD("buildInstallationConsentTest data.installationorder.uuid = %s",
              data.installationorder.uuid);
        ALOGD("buildInstallationConsentTest data.installationorder.uuid = %lu",
              strlen(data.installationorder.uuid));
        ALOGD("buildInstallationConsentTest data.installationconsent = %d",
              data.installationconsent);
        ALOGD("buildInstallationConsentTest int deltatime = %d data.deltatime = %d", deltatime,
              data.deltatime);
        ALOGD("buildInstallationConsentTest data.deltatime = %u", data.deltatime);
        ASN1C_OpInstallationConsent_Notification OpInstallationConsent_Notification(encodeBuffer,
                                                                                    data);

        if ((stat = OpInstallationConsent_Notification.Encode()) == 0) {
            if (trace) {
                ALOGD("buildInstallationConsentTest Encoding was successful\n");
                // ALOGD("buildInstallationConsentTest Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGD("buildInstallationConsentTest Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGD("buildInstallationConsentTest encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_INSTALLATION_CONSENT, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGD("buildInstallationConsentTest ipcp send success");
            }
        } else {
            ALOGE("buildInstallationConsentTest encode failed stat = %d\n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);

    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildOTAPacketTest(const OpOTAAssignmentParamHal& opOTAAssignmentParamHal) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);
    auto task = [opOTAAssignmentParamHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAAssignmentSync_Response data;
        data.m.installationorderPresent = 1;
        data.m.criticalityPresent = 1;
        data.m.purposePresent = 1;
        data.m.workshop_installiationPresent = 1;
        data.m.downloadsizePresent = 1;
        data.m.totalinstallation_timePresent = 1;
        data.m.newstatusPresent = 1;
        data.m.titlePresent = 1;
        data.m.descriptionPresent = 1;
        data.m.reasonPresent = 1;
        data.installationorder.uuid = (const char*)opOTAAssignmentParamHal.installationorder.c_str();
        data.isotimestamp.timestamp = opOTAAssignmentParamHal.timestamp.c_str();
        data.availableassignmentversion = opOTAAssignmentParamHal.availableassignmentversion.c_str();
        data.criticality = opOTAAssignmentParamHal.criticality.c_str();
        data.purpose.recall = (OSBOOL)opOTAAssignmentParamHal.purpose.recall;
        data.purpose.safety = (OSBOOL)opOTAAssignmentParamHal.purpose.safety;
        data.purpose.cybersecurity = (OSBOOL)opOTAAssignmentParamHal.purpose.cybersecurity;
        data.workshop_installiation = opOTAAssignmentParamHal.workshop_installiation;
        data.downloadsize = opOTAAssignmentParamHal.downloadsize;
        data.totalinstallation_time = opOTAAssignmentParamHal.totalinstallation_time;
        data.newstatus = opOTAAssignmentParamHal.newstatus.c_str();
        data.title = (OSUTF8CHAR*)opOTAAssignmentParamHal.title.c_str();
        data.bssid = (OSUTF8CHAR*)opOTAAssignmentParamHal.bssid.c_str();
        data.displayedversion = (OSUTF8CHAR*)opOTAAssignmentParamHal.displayedversion.c_str();
        data.description = (OSUTF8CHAR*)opOTAAssignmentParamHal.description.c_str();
        data.reason = (OSUTF8CHAR*)opOTAAssignmentParamHal.reason.c_str();

        ALOGD("buildOTAPacket data.installationorder = %s", data.installationorder.uuid);
        ALOGD("buildOTAPacket data.availableassignmentversion = %s", data.availableassignmentversion);
        ALOGD("buildOTAPacket data.isotimestamp = %s", data.isotimestamp.timestamp);
        ALOGD("buildOTAPacket data.criticality = %s", data.criticality);
        ALOGD("buildOTAPacket data.purpose.recall = %d", data.purpose.recall);
        ALOGD("buildOTAPacket data.purpose.safety = %d", data.purpose.safety);
        ALOGD("buildOTAPacket data.purpose.cybersecurity = %d", data.purpose.cybersecurity);
        ALOGD("buildOTAPacket data.workshop_installiation = %d", data.workshop_installiation);
        ALOGD("buildOTAPacket data.downloadsize = %d", data.downloadsize);
        ALOGD("buildOTAPacket data.totalinstallation_time = %d", data.totalinstallation_time);
        ALOGD("buildOTAPacket data.newstatus = %s", data.newstatus);
        ALOGD("buildOTAPacket data.title = %s", data.title);
        ALOGD("buildOTAPacket data.bssid = %s", data.bssid);
        ALOGD("buildOTAPacket data.displayedversion = %s", data.displayedversion);
        ALOGD("buildOTAPacket data.description = %s", data.description);
        ALOGD("buildOTAPacket data.reason = %s", data.reason);

        ASN1C_OpOTAAssignmentSync_Response OpOTAAssignmentSync_ResponsePDU(encodeBuffer, data);

        if ((stat = OpOTAAssignmentSync_ResponsePDU.Encode()) == 0) {
            if (trace) {
                ALOGV("buildOTAPacket Encoding was successful\n");
                // ALOGV("buildOTAPacket Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGV("buildOTAPacket Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGV("buildOTAPacket encode success");
            len = encodeBuffer.getMsgLen();
            // ALOGV("buildOTAPacket encode success len = %d", len);
            content = (char*)encodeBuffer.getMsgPtr();
            // ALOGV("buildOTAPacket encode success content = %s", content);
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_ASSIGNMENT_SYNC, OP_TYPE_NOTIFICATION,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildOTAPacket ipcp send success");
            }
        } else {
            ALOGE("buildOTAPacket encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildOTATCAMPacketTest(
    const OpOTATCAMAssignmentParamHal& opOTATCAMAssignmentParamHal) {
    ALOGI("%s", __func__);

    lock_guard<mutex> lk(mMut);

    auto task = [opOTATCAMAssignmentParamHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTATCAMAssignmentNotification_Notification data;
        data.m.reasonPresent = 1;
        data.installationorder.uuid =
            (const char*)opOTATCAMAssignmentParamHal.installationorder.c_str();
        data.isotimestamp.timestamp = (const char*)opOTATCAMAssignmentParamHal.timestamp.c_str();
        data.newstatus = (const char*)opOTATCAMAssignmentParamHal.newstatus.c_str();
        data.reason = (const char*)opOTATCAMAssignmentParamHal.reason.c_str();

        ALOGD("buildOTATCAMPacket data.installationorder = %s", data.installationorder.uuid);
        ALOGD("buildOTATCAMPacket data.isotimestamp = %s", data.isotimestamp.timestamp);
        ALOGD("buildOTATCAMPacket data.newstatus = %s", data.newstatus);
        ALOGD("buildOTATCAMPacket data.reason = %s", data.reason);

        ASN1C_OpOTATCAMAssignmentNotification_Notification
            OpOTATCAMAssignmentNotification_NotificationPDU(encodeBuffer, data);

        if ((stat = OpOTATCAMAssignmentNotification_NotificationPDU.Encode()) == 0) {
            if (trace) {
                ALOGV("buildOTATCAMPacket Encoding was successful\n");
                // ALOGV("buildOTATCAMPacket Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                // ALOGV("buildOTATCAMPacket Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            // ALOGV("buildOTATCAMPacket encode success");
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_TCAM_ASSIGNMENT_NOTIFICATION,
                                  OP_TYPE_NOTIFICATION, IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildOTATCAMPacket ipcp send success");
            }
        } else {
            ALOGE("buildOTATCAMPacket encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildPostInstallationTest(
    const OpOTAPostInstallationParamHal& opOTAPostInstallationParamHal) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);

    auto task = [opOTAPostInstallationParamHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAPostInstallationInfonotification_Notification data;
        data.m.reasonPresent = 1;
        data.installationorder.uuid =
            (const char*)opOTAPostInstallationParamHal.installationorder.c_str();
        data.isotimestamp.timestamp = (const char*)opOTAPostInstallationParamHal.timestamp.c_str();
        data.newstatus = (const char*)opOTAPostInstallationParamHal.newstatus.c_str();
        data.reason = (const char*)opOTAPostInstallationParamHal.reason.c_str();

        ALOGD("buildPostInstallationTest data.installationorder = %s", data.installationorder.uuid);
        ALOGD("buildPostInstallationTest data.isotimestamp = %s", data.isotimestamp.timestamp);
        ALOGD("buildPostInstallationTest data.newstatus = %s", data.newstatus);
        ALOGD("buildPostInstallationTest data.reason = %s", data.reason);

        ASN1C_OpOTAPostInstallationInfonotification_Notification
            OpOTAPostInstallationInfonotification_NotificationPDU(encodeBuffer, data);

        if ((stat = OpOTAPostInstallationInfonotification_NotificationPDU.Encode()) == 0) {
            if (trace) {
                ALOGV("buildPostInstallationTest Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_POST_INSTALLATION,
                                  OP_TYPE_NOTIFICATION, IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildPostInstallationTest ipcp send success");
            }
        } else {
            ALOGE("buildPostInstallationTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildBSSIDDisplayedVersionTest(const OpBSSIDDisplayedVersionSyncHal& opBSSIDDisplayedVersionSyncHal) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);
    auto task = [opBSSIDDisplayedVersionSyncHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpBSSIDDisplayedVersionSync_Response data;

        data.bssid = (OSUTF8CHAR*)opBSSIDDisplayedVersionSyncHal.bssid.c_str();
        data.displayedversion = (OSUTF8CHAR*)opBSSIDDisplayedVersionSyncHal.displayedversion.c_str();

        ALOGD("buildBSSIDDisplayedVersionTest data.bssid = %s", data.bssid);
        ALOGD("buildBSSIDDisplayedVersionTest data.displayedversion = %s", data.displayedversion);

        ASN1C_OpBSSIDDisplayedVersionSync_Response OpBSSIDDisplayedVersionSync_ResponsePDU(encodeBuffer, data);

        if ((stat = OpBSSIDDisplayedVersionSync_ResponsePDU.Encode()) == 0) {
            if (trace) {
                ALOGV("buildBSSIDDisplayedVersionTest Encoding was successful\n");
                ALOGV("buildBSSIDDisplayedVersionTest Hex dump of encoded record:\n");
                encodeBuffer.hexDump();
                ALOGV("buildBSSIDDisplayedVersionTest Binary dump:\n");
                encodeBuffer.binDump("Data");
            }
            ALOGV("buildBSSIDDisplayedVersionTest encode success");
            len = encodeBuffer.getMsgLen();
            ALOGV("buildBSSIDDisplayedVersionTest encode success len = %d", len);
            content = (char*)encodeBuffer.getMsgPtr();
            ALOGV("buildBSSIDDisplayedVersionTest encode success content = %s", content);
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_BSSID_DISPLAYEDVERSION_SYNC, OP_TYPE_RESPONSE,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildBSSIDDisplayedVersionTest ipcp send success");
            }
        } else {
            ALOGE("buildBSSIDDisplayedVersionTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildAssignmentkeytoTargetECUTest(const OpAssignmentkeytoTargetECUHal& opAssignmentkeytoTargetECUHal) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);

    auto task = [opAssignmentkeytoTargetECUHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAAssignmentkeytoTargetECU_Request data;

        data.m.fileencryptiontypePresent = 1;
        data.installationorder.uuid = (const char*)opAssignmentkeytoTargetECUHal.installationorder.c_str();
        data.isotimestamp.timestamp = (const char*)opAssignmentkeytoTargetECUHal.isotimestamp.c_str();
        //data.secretkey = (OSUTF8CHAR*)opAssignmentkeytoTargetECUHal.key.c_str();
        data.secretkey.numocts = 3;
        data.secretkey.data[0] = 0x01;
        data.secretkey.data[1] = 0x0A;
        data.secretkey.data[2] = 0xBB;

        data.fileencryptiontype.numocts = 3;
        data.fileencryptiontype.data[0] = 0x01;
        data.fileencryptiontype.data[1] = 0x02;
        data.fileencryptiontype.data[2] = 0x03;

        ALOGD("buildAssignmentkeytoTargetECUTest    uuid = %s", data.installationorder.uuid);
        ALOGD("buildAssignmentkeytoTargetECUTest    timestamp = %s", data.isotimestamp.timestamp);
        ALOGD("buildAssignmentkeytoTargetECUTest    secretkey.data[0] = %x",data.secretkey.data[0]);
        ALOGD("buildAssignmentkeytoTargetECUTest    secretkey.data[1] = %x",data.secretkey.data[1]);
        ALOGD("buildAssignmentkeytoTargetECUTest    secretkey.data[2] = %x",data.secretkey.data[2]);
        ALOGD("buildAssignmentkeytoTargetECUTest    fileencryptiontype.data[0] = %x",data.fileencryptiontype.data[0]);
        ALOGD("buildAssignmentkeytoTargetECUTest    fileencryptiontype.data[1] = %x",data.fileencryptiontype.data[1]);
        ALOGD("buildAssignmentkeytoTargetECUTest    fileencryptiontype.data[2] = %x",data.fileencryptiontype.data[2]);

        ASN1C_OpOTAAssignmentkeytoTargetECU_Request opOTAAssignmentkeytoTargetECU_Request(encodeBuffer, data);
        if ((stat = opOTAAssignmentkeytoTargetECU_Request.Encode()) == 0) {
            if (trace) {
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_ASSIGNMENT_KEY_TO_TARGET_ECU, OP_TYPE_REQUEST,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildAssignmentkeytoTargetECUTest ipcp send success");
            }
        } else {
            ALOGE("buildAssignmentkeytoTargetECUTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildSignatureCertificateTest(const hidl_string& param) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);

    auto task = [param]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTASignatureCertificate_Request data;

        data.oTASignatureCertificate = (const char*)param.c_str();

        ALOGD("buildSignatureCertificateTest    data.oTASignatureCertificate = %s", data.oTASignatureCertificate);

        ASN1C_OpOTASignatureCertificate_Request opOTASignatureCertificate_Request(encodeBuffer, data);
        if ((stat = opOTASignatureCertificate_Request.Encode()) == 0) {
            if (trace) {
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_SIGNATURE_CERTIFICATE, OP_TYPE_REQUEST,
                                  IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildSignatureCertificateTest ipcp send success");
            }
        } else {
            ALOGE("buildSignatureCertificateTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildWriteInstallationInstructionTest(const OpOTAWriteInstallationInstructionHal& opOTAWriteInstallationInstructionHal) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);

    auto task = [opOTAWriteInstallationInstructionHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        const std::string bssid("123456789123456789123456789123456789123456");//size42
        const std::string displayedversion("123456789123456789123456789123456789123456789123456789123456");//size60
        const std::string validtime("41704532219831327688412");//size23

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAWriteInstallationInstructions_Request data;
        data.installationinstruction.m.operationsequencePresent = 1;
        data.installationorder.uuid = (const char*)opOTAWriteInstallationInstructionHal.installationorder.c_str();
        data.installationinstruction.installationinstructionsversion = "123123";//size6
        data.installationinstruction.bssid = (OSUTF8CHAR*)bssid.c_str();
        data.installationinstruction.displayedversion = (OSUTF8CHAR*)displayedversion.c_str();
        
        ALOGD("%s:  uuid = %s ", __func__,  data.installationorder.uuid);
        ALOGD("%s:  installationinstructionsversion = %s ", __func__,  data.installationinstruction.installationinstructionsversion);
        ALOGD("%s:  bssid = %s ", __func__,  data.installationinstruction.bssid);
        ALOGD("%s:  displayedversion = %s ", __func__,  data.installationinstruction.displayedversion);

        data.installationinstruction.area1112securitycode.securitykey.numocts = 16;
        for (size_t i = 0; i < 16; i++) {
            data.installationinstruction.area1112securitycode.securitykey.data[i] = 0x00;
        } 

        data.installationinstruction.ecuinstructions.ecuaddress.addr.numocts = 2;
        data.installationinstruction.ecuinstructions.ecuaddress.addr.data[0] = 0x12;
        data.installationinstruction.ecuinstructions.ecuaddress.addr.data[1] = 0x02;
        data.installationinstruction.ecuinstructions.securitycode.securitykey.numocts = 16;
         for (size_t i = 0; i < 16; i++) {
            data.installationinstruction.ecuinstructions.securitycode.securitykey.data[i] = 0x00;
        } 
        data.installationinstruction.ecuinstructions.sblnotpresent = opOTAWriteInstallationInstructionHal.sblnotpresent;
        data.installationinstruction.ecuinstructions.m.sblnotpresentPresent = 1;

        data.installationinstruction.assignmentvalidationpre.clientversion.uuid = (const char*)opOTAWriteInstallationInstructionHal.installationorder.c_str();
        data.installationinstruction.assignmentvalidationpost.ecuaddress.addr.numocts = 2;
        data.installationinstruction.assignmentvalidationpost.ecuaddress.addr.data[0] = 0x12;
        data.installationinstruction.assignmentvalidationpost.ecuaddress.addr.data[1] = 0x02;

        ALOGD("%s:  sblnotpresent = %d ", __func__,  data.installationinstruction.ecuinstructions.sblnotpresent);

        if (opOTAWriteInstallationInstructionHal.dataList.size() > 0) {
            ASN1C_Ecuinstructionsdata_softwarepartinstallationinstruction softwarepartinstallationinstructionList(
                        data.installationinstruction.ecuinstructions.softwarepartinstallationinstruction);
            
            for (size_t i = 0; i < opOTAWriteInstallationInstructionHal.dataList.size(); i++) {
                ASN1T_SoftwarePartInstallationInstruction* softwarepartinstallationinstruction = 
                softwarepartinstallationinstructionList.AppendNewElement();

                softwarepartinstallationinstruction->m.flashgroupidPresent = 1;
                softwarepartinstallationinstruction->m.downloadtypePresent = 1;
                softwarepartinstallationinstruction->m.installationtypePresent = 1;
                softwarepartinstallationinstruction->m.fileencryptiontypePresent = 1;
                softwarepartinstallationinstruction->m.validtimePresent = 1;
                softwarepartinstallationinstruction->m.validdatePresent = 1;

                softwarepartinstallationinstruction->filename.name = (OSUTF8CHAR*)validtime.c_str();//(OSUTF8CHAR*)opOTAWriteInstallationInstructionHal.dataList[i].filename.c_str();
                softwarepartinstallationinstruction->downloadtype = (const char*)opOTAWriteInstallationInstructionHal.dataList[i].downloadtype.c_str();
                softwarepartinstallationinstruction->installationtype = (const char*)opOTAWriteInstallationInstructionHal.dataList[i].installationtype.c_str();
                softwarepartinstallationinstruction->fileencryptiontype = (const char*)opOTAWriteInstallationInstructionHal.dataList[i].fileencryptiontype.c_str();
                softwarepartinstallationinstruction->estimatedinstallationtime = opOTAWriteInstallationInstructionHal.dataList[i].estimatedinstallationtime;
                softwarepartinstallationinstruction->validtime = (const char*)validtime.c_str();
                
                ALOGD("%s: i = %zu  filename.name = %s ", __func__, i,  softwarepartinstallationinstruction->filename.name);
                ALOGD("%s: i = %zu  downloadtype = %s ", __func__, i,  softwarepartinstallationinstruction->downloadtype);
                ALOGD("%s: i = %zu  installationtype = %s ", __func__, i,  softwarepartinstallationinstruction->installationtype);
                ALOGD("%s: i = %zu  fileencryptiontype = %s ", __func__, i,  softwarepartinstallationinstruction->fileencryptiontype);
                ALOGD("%s: i = %zu  estimatedinstallationtime = %d ", __func__, i,  softwarepartinstallationinstruction->estimatedinstallationtime);
            }
        }

        ASN1C_OpOTAWriteInstallationInstructions_Request opOTAWriteInstallationInstructions_Request(encodeBuffer, data);

        if ((stat = opOTAWriteInstallationInstructions_Request.Encode()) == 0) {
            if (trace) {
                ALOGV("buildWriteInstallationInstructionTest Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_WRITE_INSTALLATION_INSTRUCTION,
                                  OP_TYPE_REQUEST, IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildWriteInstallationInstructionTest ipcp send success");
            }
        } else {
            ALOGE("buildWriteInstallationInstructionTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildAssignmentFileInfoTest(const OpOTASetAssignmentFileInfoHal& opOTASetAssignmentFileInfoHal) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);

    auto task = [opOTASetAssignmentFileInfoHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;
        const std::string validtime("41704532219831327688412");//size23

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTASetAssignmentFileInfo_Request data;
        data.installationorder.uuid = (const char*)opOTASetAssignmentFileInfoHal.installationorder.c_str();
        data.ecuaddress.addr.numocts = 2;
        data.ecuaddress.addr.data[0] = 0x12;
        data.ecuaddress.addr.data[1] = 0x02;
        data.lastsegment = opOTASetAssignmentFileInfoHal.lastsegment;

        ALOGD("%s:  uuid = %s ", __func__,  data.installationorder.uuid);
        ALOGD("%s:  lastsegment = %d ", __func__,  data.lastsegment);

        if (opOTASetAssignmentFileInfoHal.dataList.size() > 0) {
            ASN1C__SetOfAssignmentFileInfo  assignmentFileInfoList(data.assignfileinfo);

            for (size_t i = 0; i < opOTASetAssignmentFileInfoHal.dataList.size(); i++) {
                ASN1T_AssignmentFileInfo* assignfileinfo = assignmentFileInfoList.AppendNewElement();

                assignfileinfo->m.flashgroupidPresent = 1;
                assignfileinfo->m.downloadtypePresent = 1;
                assignfileinfo->m.installationtypePresent = 1;
                assignfileinfo->m.fileencryptiontypePresent = 1;
                assignfileinfo->m.validtimePresent = 1;
                assignfileinfo->m.validdatePresent = 1;

                assignfileinfo->filename.name = (OSUTF8CHAR*)opOTASetAssignmentFileInfoHal.dataList[i].filename.c_str();

                //assignfileinfo->downloadtype = (const char*)opOTASetAssignmentFileInfoHal.dataList[i].downloadtype.c_str();
                assignfileinfo->downloadtype.numocts = 1;
                assignfileinfo->downloadtype.data[0] = 0x01;//Download to target ECU

                //assignfileinfo->installationtype = (const char*)opOTASetAssignmentFileInfoHal.dataList[i].installationtype.c_str();
                assignfileinfo->installationtype.numocts = 1;
                assignfileinfo->installationtype.data[0] = 0x01;//Distributed installation

                assignfileinfo->softwarepartsignature.softwarepartsignature1.numocts = 64;
                for(size_t i = 0; i < 64; i++ ) {
                    assignfileinfo->softwarepartsignature.softwarepartsignature1.data[i] = i;
                }
                assignfileinfo->filechecksum.numocts = 4;
                for(size_t i = 0; i < 4; i++ ) {
                    assignfileinfo->filechecksum.data[i] = 0x02;
                }
                assignfileinfo->validtime = (const char*)validtime.c_str();

                ALOGD("%s: i = %zu  filename.name = %s ", __func__, i,  assignfileinfo->filename.name);
                ALOGD("%s: i = %zu  downloadtype = %x ", __func__, i,  assignfileinfo->downloadtype.data[0]);
                ALOGD("%s: i = %zu  installationtype = %x ", __func__, i,  assignfileinfo->installationtype.data[0]);
            }
        }

         ASN1C_OpOTASetAssignmentFileInfo_Request opOTASetAssignmentFileInfo_Request(encodeBuffer, data);

         if ((stat = opOTASetAssignmentFileInfo_Request.Encode()) == 0) {
            if (trace) {
                ALOGV("buildAssignmentFileInfoTest Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_SET_ASSIGNMENT_FILE_INFO,
                                  OP_TYPE_REQUEST, IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildAssignmentFileInfoTest ipcp send success");
            }
        } else {
            ALOGE("buildAssignmentFileInfoTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };
    
    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildRVDCTransferLogsCRCTest(const hidl_string& logname, const hidl_string& logcrc) {
    auto task = [logname, logcrc]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpRVDCTransferLogsCRC_Request data;
        data.logname.name = (OSUTF8CHAR*)logname.c_str();
        data.logcrc.numocts = 4;
        data.logcrc.data[0] = 0x12;
        data.logcrc.data[1] = 0x02;
        data.logcrc.data[2] = 0x12;
        data.logcrc.data[3] = 0x02;

        ALOGD("buildRVDCTransferLogsCRCTest data.logname = %s", data.logname.name);

        ASN1C_OpRVDCTransferLogsCRC_Request opRVDCTransferLogsCRC_Request(encodeBuffer, data);
        if ((stat = opRVDCTransferLogsCRC_Request.Encode()) == 0) {
            if (trace) {
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet = build_ipcp_packet(SERVICE_ID, OP_ID_RVDC_TRANSFER_LOGS_CRC,
                                    OP_TYPE_REQUEST, IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildRVDCTransferLogsCRCTest ipcp send success");
            }
        } else {
            ALOGE("buildRVDCTransferLogsCRCTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

Return<StatusCode> Ota::buildRVDCLogInterruptedDataTransferRetryTest(const hidl_string& logname) {
    auto task = [logname]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpRVDCLogInterruptedDataTransferRetry_Request data;
        data.logname.name = (OSUTF8CHAR*)logname.c_str();

        ALOGD("buildRVDCLogInterruptedDataTransferRetryTest data.logname = %s", data.logname.name);

        ASN1C_OpRVDCLogInterruptedDataTransferRetry_Request opRVDCDataTransferRetry_Request(encodeBuffer, data);
        if ((stat = opRVDCDataTransferRetry_Request.Encode()) == 0) {
            if (trace) {
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet = build_ipcp_packet(SERVICE_ID, OP_ID_RVDC_LOG_TRANSFER_RETRY,
                                    OP_TYPE_REQUEST, IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildRVDCLogInterruptedDataTransferRetryTest ipcp send success");
            }
        } else {
            ALOGE("buildRVDCLogInterruptedDataTransferRetryTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

int Ota::bytesToInt(u_int8_t* bytes) {
    int data = bytes[3];
    data |= (bytes[2] << 8);
    data |= (bytes[1] << 16);
    data |= (bytes[0] << 24);
    return data;
}
// TODO
Return<bool> Ota::getVerifySignatureStatus() {
    FILE *file;
    file = fopen("/dev/block/vdn","rb");
    if ( file == nullptr) {
        ALOGE("Can not open : dev/block/vdn" );
        return false;
    } else {
        fseek(file,51*512,SEEK_SET);
        u_int8_t data[5];
        fread(data,5,1,file);
        ALOGD("data[0~5] : %x, %x, %x, %x, %x", data[0],data[1],data[2],data[3], data[4]);

        unsigned int validStatus = (unsigned int)bytesToInt(data);
        if (validStatus == 0x87654321) {
            ALOGD("magic number is valid : %x", validStatus);
            if (data[4] == 0x00) {
                return true;
            } else {
                return false;
            }
        } else {
            ALOGE("magic number is invalid : %x", validStatus);
            return false;
        }
    }
}

Return<StatusCode> Ota::buildURLInfoTest(const OpOTAURLInfoReqHal& opOTAURLInfoReqHal) {
    ALOGI("%s", __func__);
    lock_guard<mutex> lk(mMut);

    auto task = [opOTAURLInfoReqHal]() {
        const char* content = NULL;
        int stat, len;
        bool trace = FALSE;
        ipcp_stack_err_t err;

        ASN1PEREncodeBuffer encodeBuffer(false);
        ASN1T_OpOTAURLInfo_Request data;

        data.m.downloadtypePresent = 1;
        data.m.encryptinfoPresent = 1;
        data.m.encryptiontypePresent = 1;
        data.m.fileSizePresent = 1;
        data.m.specifiedurlPresent = 1;

        data.installationorder.uuid = (const char*)opOTAURLInfoReqHal.installationorder.c_str();

        //data.downloadtype = (const char*)opOTAURLInfoReqHal.downloadtype.c_str();
        data.downloadtype.numocts = 1;
        data.downloadtype.data[0] = 0x01;//Download to target ECU

        //data.encryptinfo = (const char*)opOTAURLInfoReqHal.encryptinfo.c_str();
        data.encryptinfo.numocts = 1;
        data.encryptinfo.data[0] = 0x01;//Encryption method 1   information

        //data.encryptiontype = (const char*)opOTAURLInfoReqHal.encryptiontype.c_str();
        data.encryptiontype.numocts = 1;
        data.encryptiontype.data[0] = 0x01;//Encryption method 1

        data.ecuaddress.addr.numocts = 2;
        data.ecuaddress.addr.data[0] = 0x12;
        data.ecuaddress.addr.data[1] = 0x02;

        data.fileSize = opOTAURLInfoReqHal.fileSize;
        
         if (opOTAURLInfoReqHal.urlList.size() > 0) {
            ASN1C__SetOfSpecifiedurl  specifiedurlList(data.specifiedurl);

            for (size_t i = 0; i < opOTAURLInfoReqHal.urlList.size(); i++) {
                ASN1T_Specifiedurl* specifiedurl = specifiedurlList.AppendNewElement();
                specifiedurl->url = (OSUTF8CHAR*)opOTAURLInfoReqHal.urlList[i].url.c_str();
                ALOGD("%s: i = %zu  specifiedurl = %s ", __func__, i,  specifiedurl->url);
            }
        }

        ASN1C_OpOTAURLInfo_Request opOTAURLInfo_Request(encodeBuffer, data);

        if ((stat = opOTAURLInfo_Request.Encode()) == 0) {
            if (trace) {
                ALOGV("buildURLInfoTest Encoding was successful\n");
                encodeBuffer.hexDump();
                encodeBuffer.binDump("Data");
            }
            len = encodeBuffer.getMsgLen();
            content = (char*)encodeBuffer.getMsgPtr();
            ipcp_packet_t* packet =
                build_ipcp_packet(SERVICE_ID, OP_ID_OTA_URL_INFO,
                                  OP_TYPE_REQUEST, IPCP_DATA_ENCODED, (void*)content, len);
            if ((err = ipcp_send(peer_ota_server_test, packet)) != STACK_SEND_MSG_SUCCESS) {
                ALOGE("%s: ipcp_send err : %d", __FUNCTION__, err);
            } else {
                ALOGV("buildURLInfoTest ipcp send success");
            }
        } else {
            ALOGE("buildURLInfoTest encode failed error stat = %d \n", stat);
            encodeBuffer.printErrorInfo();
        }
    };

    mThread.schedule(task, gDefaultDelay.common);
    return StatusCode::SUCCESS;
}

void Ota::handleHidlDeath() {
    ALOGD("%s", __func__);
    sp<Ota> ota = Ota::getOta(cookie);
    sp<IOtaClientCallback> callback = ota->getCallback();
    unsubscribe(callback);
    ipcp_cleanup();
    // setupDtcnl();
}
//------------------------- OTA TEST END -------------------------
//----------------------------------------------------------------

}  // namespace V1_0
}  // namespace ota
}  // namespace xma
}  // namespace ecarx
}  // namespace vendor
